• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Stateless EJB and transactions

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic