This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes Stateless EJB and transactions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Stateless EJB and transactions" Watch "Stateless EJB and transactions" New topic
Author

Stateless EJB and transactions

Selvan tiru
Greenhorn

Joined: Jul 12, 2001
Posts: 18
Hello:
Reading an article on EJB at
http://www.onjava.com/pub/a/onjava/excerpt/bldgjavaent_8/index3.html?page=3
Can somebody correct my understanding from this article: The author writes about changing a stateful session bean to stateless EJB and both
access Entity bean.
Q. In BMP how are transactions managed if none of the EJB callback methods are implemented and no session contex is initialized. and in the deployment descriptor traction type = container : <transaction-type>Container</transaction-type>.
For this case, if I have traction type = Bean
without initializing transaction context, is the bean set to handle transactions
i.e in any BMP if the transaction context is not set how does the EJB handle transactions?

Q. For CMP there is no need to implement callback methods. but the deployment descriptor traction type must be = container : <transaction-type>Container</transaction-type>. Is this correct
Q. If session beans and data access beans ( no entity beans)are used in the application design where or how does the transaction logic works?
Thanks
Selvan
Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
Q. In BMP how are transactions managed if none of the EJB callback methods are implemented and no session contex is initialized. and in the deployment descriptor traction type = container : <transaction-type>Container</transaction-type>.

EJB Callback methods (ejbActivate, ejbCreate, etc) are not related to transactions. Your holding the SessionContext has no impact on container managed transactions. The container will still start/commit/rollback transactions based on your transaction-attribute setting (Required, Supports, etc.) no matter what you implement.
For this case, if I have traction type = Bean
without initializing transaction context, is the bean set to handle transactions
i.e in any BMP if the transaction context is not set how does the EJB handle transactions?

To do Bean-managed transactions (which I don't recommend unless you absolutely must), you will need to get the UserTransaction object from the SessionContext, thus you should implement setSessionContext to keep the context. As in:

Q. For CMP there is no need to implement callback methods. but the deployment descriptor traction type must be = container : <transaction-type>Container</transaction-type>. Is this correct
Correct. The container will manage the transactions for you.
Q. If session beans and data access beans ( no entity beans)are used in the application design where or how does the transaction logic works?
For this, you mark the transaction attribute on the Session Bean and let the container manage it. As long as the data access is done using a TxDataSource obtained in a J2EE compliant way, then those JDBC calls will be included in the transaction. That is, use the JDBC Connection you get from TxDataSource, and get the data source from JNDI via a res-ref setting, as in "java:comp/env/MyDataSource".
Hope it helps.
-- Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Stateless EJB and transactions
 
Similar Threads
ejb question
Answers of Sun's Free Proficiency Assessment
Download option in JSP
error while deploying ejb in jboss
Urgent help needed - Thanks