Hi all, according to EJB 1.1 specifications there are two "potential" methods where resource can be acquired in an Entity bean:
public void ejbActivate(); "The ejbActivate() method gives the entity bean instance the chance to acquire additional resources that it needs while it is in the ready state."
public void setEntityContext(EntityContext ic); "The instance can take advantage of the setEntityContext() method to allocate any resources that are to be held by the instance for its lifetime. Such resources cannot be specific to an entity object identity because the instance might be reused during its lifetime to serve multiple entity object identities."
It seems that the only difference is that setEntityContext is called prior (when the bean is still in the pool) to ejbActivate.
But should you have the question in the Subject on the quiz-day what should you vote for ?
Originally posted by Francesco Marchioni: But should you have the question in the Subject on the quiz-day what should you vote for ? a) ejbActivate b) setEntityContext
setEntityContext - because ejbActivate will not be called when the bean moves from "pooled" to "ready" through the ejbCreate/ejbPostCreate call. Take a look at the "Life cycle of an entity bean instance" diagram.
Under different circumstances (where you need to shorten the holding time) you may want to call an acquisition helper method from both ejbCreate/ejbPostCreate and ejbActivate; then call a release helper method from ejbPassivate and ejbRemove. However under these circumstances you would probably call both helper methods from the business methods that use the resources - unless resource acquisition and release are extemely expensive and/or time consuming.
And when my army is complete, I will rule the world! But, for now, I'm going to be happy with this tiny ad: