• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Doubt in stateful session bean

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Is there anything called container managed session bean and bean managed session bean ?

If so, can anyone explain me the importance and which one is the default for session bean.
 
Sheriff
Posts: 3034
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are container-managed transactions and bean-managed transactions for session beans. Container-managed persistence and bean-managed persistence are only for entity beans. For CMT vs. BMT, there is no default, but I'd say CMT is more common.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just to add, for more clearification. BMT vs CMT. It's just way
of classifying beans basesd on how they manage there transactiions.
For BMT, you are to the container that that YOU, the bean provider
is going to manage the bean transaction (tx) yourself. And For CMT, you get
telling the Container, Hey, please manage my bean transction for me, and
the Container reply HOW. You just say check my bean DD for instructions on how.
To add more, for BMT, you just have to use the javax.transaction.UserTransaction interface, while for CMT, you have
to use the setRollbackOnly() and getRollbackOnly() from EJBContext. eg

BMT

UserTransaction ut = EJBContext.getUserTransaction(); // get the tx
ut.begin() // start the tx
foo();
bar();
if(allIsFine){
ut.commit(); // commit tx
} else {
ut.rollback(); // rollback tx
}

CMT

It's more of declarative, it has only two methods that
you can use to manage your tx and they are handled on methods bases.

if (allAnyBad) {
EJBContext.setRollbackOnly(); // tx will never commit.
}
To check for tx status,

BMT

ut.getStatus();

CMT

EJBContext.getRollbackOnly();

Hope the difference is clear.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


For BMT, you are to the container that that YOU, the bean provider
is going to manage the bean transaction (tx) yourself. And For CMT, you get telling the Container, Hey, please manage my bean transction for me, and the Container reply HOW.


This is not correct. The Container always manages the transaction. The difference between BMT and CMT is about demarcation. For BMT, the enterprise bean transaction demarcation is done programmatically in the business methods, for CMT the transaction demarcation is done by the Container based on the transaction attributes in the deployment descriptor.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!