The following confused me while reading the EJB 2.0 specs. In 7.5.7 it states that a session bean's ejbCreate and ejbRemove are called within an unspecificied transaction. In 7.6.1 I read that accessing resource managers and enterprise beans is dissallowed in the session bean's methods for which the Container does not have a meaningful transaction context. But the table on page 80 allows accessing resource managers and enterprise beans in the ejbCreate and ejbRemove methods. Does this mean that an unspecified transaction is a meaningful transaction?
[I have edited my answer regarding stateful session beans]
The transaction context in ejbCreate and ejbRemove depends on the type of bean you are looking at. For entity beans, the containers call to the ejbCreate and ejbRemove methods is related to the client call and can therefore participate in the caller�s transaction and therefore access resource managers other enterprise beans etc. For stateless session beans and message driven beans the containers call to the ejbCreate and ejbRemove methods is not related to a client call and can therefore not participate in the caller�s transaction, in other words the transaction context is unspecified, i.e. you cannot write code that depends on a transaction being present.
For stateful session beans the transaction is also unspecified in ejbCreate and ejbRemove but the explanation given above does not apply here because the containers call to ejbCreate and ejbRemove is related to the client call. The spec gives the following reason (page 76) ----- �. The ejbCreate and ejbRemove methods are not controlled by a transaction attribute because handling rollbacks in these methods would greatly complicate the session instance�s state diagram. �. ----- So for statefull session beans you can access resource managers and enterprise beans in ejbCreate and ejbRemove in a way that do not depend on a transaction being present.
Kind regards Christian [ July 09, 2004: Message edited by: Christian Sellberg ]
Joined: Jul 16, 2003
Thanks Christian. Your explanation makes a lot more sense than the remarks in 7.5.7 and 17.6.5 about the transaction context of a session bean's ejbCreate en ejbRemove methods.