Why is #4 not right? I think you can get a "reference" to Resource Manager in setEntityContext (You can even get a "reference" to a connection) and agree that you might not be able to use it.
Please suggest. Turn to page 196 in HFEJB if need be...
=========================================================================== Which of the following are valid operations in the setEntityContext method, after the CMP entity bean has been instatantiated?
incorrect, you chose answers 1, 3, 4. The correct answers are 1,3.
1) Get a reference to your home interface. 2) Get a reference to your EJBObject. 3) Get a reference to your JNDI environment. 4) Get a reference to the resource manager. 5) Get security related information about the calling client application.
Answers 1 and 3 are correct.
An entity bean instance's life starts when the container creates the instance using newInstance(). The container then invokes the setEntityContext() method to pass the instance a reference to the EntityContext interface. The EntityContext interface allows the instance to invoke services provided by the container and to obtain the information about the caller of a client-invoked method.
At this moment the only valid operations within the setEntityContext() method are:
getting a reference to your home with getEJBHome() or getEJBLocalHome(). having access to your JNDI environment. It is not possible to get a reference to your EJBObject or to get security information about the client at this moment. If the entity bean tries to access methods that are not allowed then the container will throw an IllegalStateException. ===========================================================================
I don't think option # 4 is correct b'coz it is too early to access a database in setEntityContext() method. Please refer to page 327 in HFEJB (page 197 corresponds to sessionbean, setSessionContext()) for reference or the spec.
posted 13 years ago
Tks for the response. "Accessing a resource like database" is different from "getting a reference to a resource like database". In setEntityContext, you can get a reference to the resource, which is this question about, but in setEntityContext you cannot use that reference to access the database. In page 197, it is clerly explained that getting a reference is different from accessing the resource using the reference. I am sorry for not conveying clearly what I was thinking, but the above was my intent. So, now suggest, if #4 is right or wrong.
For accessing any resource manager we need to have a meaning full transaction. setEntityContext method always runs in an unspecified transaction context. That is the reason accessing resource manager are restricted in setEntityContext.
Thanks again. This question is not about "accessing" a resource manager, but "just getting" a reference to the resource manager, which is just nothing but accessing your JNDI environment. Accessing bean's environment is allowed in setEntityContext. I completely agree that you cannot use the connection you got from a DataSource, to execute a query in setEntityContext and I believe the question is not about that.
I think I am missing something and please clarify...
Thanks a ton Vijay.
Is this the real life? Is this just fantasy? Is this a tiny ad?