I am having confusion over understanding bean things. The life cycle of stateless session bean and MessageDrivenBean is more or less same. In case of MDB, we can access getUserTransaction in ejbCreate/ejbRemove methods. But not in stateless session bean's ejbCreate/ejbRemove method. Why?
What are the rules for accessing getuserTransaction() method?
Prashant,this is a tricky thing. Actually if you look carefull at the spec you realise that SLSB and MDB are the same from the getUserTransaction() point of view.
So here it is a summary:
1. SLSB and MDB, are both allowed to call getUserTransaction() in ejbCreate() and ejbRemove() but they are not alowed to use it! That is why Kathy, on pg 228, puts these two things together: "get a transaction reference and call methods on it (BMT)" - is not allowed! See also pg 90 and 320 in the spec. 2. SFSB are alowed both to call getUserTransaction() and to call methods on it (see pg. 80).
However, to make it even more confusing, it is definately not recommended to use the UserTransaction even if you can, for SFSB, since they run in an UTC(unspoecified tx context). 7.5.6, pg 76.
Personally I think the spec could have dealed in the same way with getUserTransaction() as with "Resource manager access". Just say that you can not acess the user transaction in ejbCreate() and ejbRemove() for SLSB and MDB. Not to specify that you can call the getUSerTransaction() method, but you can not use the UserTransaction. Because you can look up a resource manager connection factory, and you can get a connection in ejbCreate() and ejbRemove(). But still you can not make JDBC calls on it!