I have 2 questions regarding what is allowed/disallowed for a Stateful/Stateless bean. It would be great if someone could answer them.
1. setRollbackOnly() and getRollbackOnly() of the SessionContext. 2. Accessing other enterprise beans and resource Managers.
The EJB spec says (1) and (2) cannot happen if the container does not have a meaningful transaction context. But, I could see that the ejbCreate, ejbRemove, ejbActivate, ejbPassivate methods for stateful session bean allows (2) but disallows (1). How is (2) allowed if the container is in unspecified transaction context ?
b. The EJB spec says the stateless session bean can get a reference to EJBObject in its ejbCreate() method. My question is : For a stateless session beans, Only when client calls create() on the Home, will the EJBObject be created ( atleast that what we should visualize) and the bean creation is not tied to client's create() call ( i.e the bean could have been in the pool long before the client's create() call.) If this is the case, there wont be any EJBObject during ejbCreate. So How can SessionContext.getEJBObject() possible during ejbCreate Call ? Let me know if I am right on my assumptions.
Look at the book errata page. I saw some notes about stateful/stateless session bean creation corrections. I too have the same doubt. Appreciate if you anyone can explain this. I will go through the errata page and I will explain this later.
I forgot to mention the book "Head First EJB" that I was using. I hope you have implied the errata for this book only. If that is the case, I did find some error related to create() call but that was for Stateful Session bean and not for Stateless session bean.
Regarding the accessing EJB Object in ejbCreate() of SLSB, Looks like there were a lot of hot discussion about this topic and no one has a definite answer for this. Everyone assumed that when the bean is created there is a **TEMP** ejb object which the bean calls to get the reference. But for sure it is inconsistent with the diagram.
It is given in EJB Sepc page-81 the stateful session beans create()ejbPassivate()/ejbActivate()/remove() execute in unspacified transaction context. so the transaction related method of the EJBObject can not be called.
But The all these methods execute in client security the context.
And EJB Spec says that Transaction or the security context is reqired to access the resoureces. Keep in mind the resources can be any type of resources not only the resources that reqiure transaction and not all resources require transaction context but every one requires the security context to access the resources for the security reasons.
Thanks!! Sandeep Vaid
Rototillers convert rich soil into dirt. Please note that this tiny ad is not a rototiller: