This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes A basic Question on ejbLoad and ejbStore Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "A basic Question on ejbLoad and ejbStore" Watch "A basic Question on ejbLoad and ejbStore" New topic
Author

A basic Question on ejbLoad and ejbStore

kalpana Kumar
Ranch Hand

Joined: Jul 03, 2003
Posts: 65
All,
The J2EE tutorial says,
"If a business method is associated with a transaction, the container invokes ejbLoad before the business method executes. Immediately after the business method executes, the container calls ejbStore."

I have many entity beans in my application and they are accessed within the session bean's business method.
So, the transaction starts when the session bean is created.
My question is when "before the business method is executed,is mentioned" does it mean before the invokation of the business method?, so when the session bean's instance is created??
Does the container invoke the ejbLoad's of all the Entity beans in the entire application as soon an instance of the session bean is created??.
Pl I need a detailed explanation so that I can understand better.

Thanks in Advance
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
Hi Kalpana,


So, the transaction starts when the session bean is created.

No. The transactions usually start when business methods are invoked. Here you have to understand that entity ejbs are not allowed to start/stop transactions. The reason is exactly the one you mentioned: the container needs to call ejbLoad at the beginning of the transaction and ejbStore before committing the transaction. If entity ejbs would be allowed to start/commit transactions then they should do that inside of the ejbLoad/ejbStore methods. As you might guess the container cannot honor such a contract. Hence the transaction could be started on the server, calling methods on the session fa�ade for example, or it could be started on the client. The way the transactional context propagates from one ban to the other depends whether you�re using CMT (see transaction attributes) or BMT.

My question is when "before the business method is executed,is mentioned" does it mean before the invokation of the business method?, so when the session bean's instance is created??

Usually clients get the beans after running a finder. The container takes a bean instance from the pool in order to run the finder, gets the bean instances that satisfies the finder�s criteria, caches them and calls ejbLoad to synchronize the data with the database. Now the clients (they could be other beans as well) are free to invoke business methods on that bean.

Does the container invoke the ejbLoad's of all the Entity beans in the entire application as soon an instance of the session bean is created??.

I deliberately bolded all the references you made to the session beans creation, in the context of asking about ejbLoad/ejbStore methods of the entity beans. I want you to understand that they are not related in any way. Entity beans have nothing to do with the way session beans are created or vice versa. The only way they get related is when a session bean acts as a client calling business methods of one or more entity beans. How the transaction gets created and propagated I already provided you some hints.
Regards.


I think, therefore I exist -- Rene Descartes
kalpana Kumar
Ranch Hand

Joined: Jul 03, 2003
Posts: 65
Thanks a lot Valentin
Valentin Tanase
Ranch Hand

Joined: Feb 17, 2005
Posts: 704
You're very welcome Kalpana
 
Consider Paul's rocket mass heater.
 
subject: A basic Question on ejbLoad and ejbStore
 
Similar Threads
ejbStore() and ejbLoad() in Entity Beans
Contradiction in Head First EJB ?
Entity beans CMP demarcation...
When are ejbLoad and ejbStore called?
ejbLoad() and ejbStore()