Hi, i got a question over an Entity EJB (BMP or CMP as they life-cicle is pretty much the same) life-cicle. I've search over some books and there's a step that all of them seem to miss (or just don't be to explicit). There are 3 stages for an entity EJB. - no state - pool - ready The transition i'd like some help is the pool -> ready transition. When i use ejbCreate() is pretty simple, that's not the case. Then, there're only left one more way, through the ejbActivate() -> ejbLoad() methods. Here's my point... All the books i read describe the ejbFind() methods being on the pool stage (an arrow coming from it and going to it). This is exactly where i disagree! Suppose i have a CMPon pool rigth now and i also have a SessionBean holding a reference to that CMPLocalHome interface. Note that at this point, the CMP is still on pool. Then, from my client, i call a method on SessionBean that does something like the following.
As u can see, i just obtained a Local interface from the LocalHome interface i had before. After that, i called a getter method of the CMP bean, by that its pretty obvious that my CMP bean has got to be transitioned to the ready state, as it was associated with database data. Here goes my question, When exactly did the container called ejbActivate() -> ejbLoad()??? In other words, how exactly did my CMP bean get to the ready stage? Thank you so much, ltcmelo
After the ejbFind<METHOD>(...) method completes, the instance remains in the pooled state. The container may, but is not required to, activate the objects that were located by the finder using the transition through the ejbActivate() method. The container invokes the ejbActivate() method on an instance when an instance needs to be activated to service an invocation on an existing entity object this occurs because there is no suitable instance in the ready state to service the client�s call. (This happens due to ur business method call). Note that instance is not yet ready for the delivery of a business method. The container must still invoke the ejbLoad() method prior to a business method. So once you call a business method the continer would have called the ejbActivate and then ejbLoad. Hope this answers your question.
Moreover, in the above case the bean instance in the pooled state that executed the finder method() may not be the same instance to transition to the ready state and execute the business method. The 2 methods could be executed by 2 different entity beans of the same type in the pooled state. One bean could execute the finder method in the pooled state and the same bean or another bean of the same type in the pooled state could transition to the Ready state by calling ejbActivate(), ejbLoad() and execute the business method. I think this is vendor-specific.
Your comments are substancious, but, consequently, i now come up with the following question. Follow my thougths. When i call the ejbFind() method, i call it on a bean that is on the pool. All the entities EJB life-cicle diagrams i`ve seen, show the bean still on the pool after the ejbFind() method, wich means that just AFTER the ejbFind() the beans is NOT yet associated to any database data. That`s what the literature says. The point is... i got returned from ejbFind() method a LocalInterface for a Bean, wich means that the bean is NOW associated with database data, as i have NOW a local interfaces that i can call any business (or setter and getter ) method of that bean. As you all said, the bean must have passed through the ejbActivate() -> ejbLoad() methods (supposing there was no other bean in the ready state). One way i can think of that is that the container invoked ejbActivate() -> ejbLoad() just AFTER any invokation of any finder method. I cannot view it in other way ( is ther any other way??? ) ! So, why is it not part of the j2ee specification ( i mean, something that specifies to "always call ejbActivate() -> ejbLoad after any finder method"??? Thanks, ltcmelo
Originally posted by Leandro Melo: The point is... i got returned from ejbFind() method a LocalInterface for a Bean, wich means that the bean is NOW associated with database data, as i have NOW a local interfaces that i can call any business (or setter and getter ) method of that bean.
This, I believe, is your error. Having a local interface for an entity bean doesn't necessarily mean it points to a bean in the ready state. When you first call a business method on the interface, the container enlists a real bean into the transaction to perform the method. It is at this point that ejbLoad() gets called to bring in the data.
Really a mistake! Got the point now! I'd say now that with the local interface i got an "identification" of a bean, but not itself yet. After that, when i call a business method, the container is alerted and thus call ejbActivate() -> ejbLoad() (in the case there is no bean in ready stage). Thanks, ltcmelo
We should throw him a surprise party. It will cheer him up. We can use this tiny ad: