This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Doubt in stateful session bean Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "Doubt in stateful session bean" Watch "Doubt in stateful session bean" New topic
Author

Doubt in stateful session bean

Shanmugam Karthikeyan
Ranch Hand

Joined: Aug 02, 2002
Posts: 58
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.


SCJP 1.4<br />SCWCD 1.4<br />SCBCD 1.3
Greg Charles
Bartender

Joined: Oct 01, 2001
Posts: 2542
    
  10

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.
MI Mohammed
Ranch Hand

Joined: Feb 16, 2005
Posts: 146
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.


SCJA(Beta) SCJP 1.4 SCWCD 1.4 SCBCD 1.3 SCBCD 5.0 beta <br />The more practice we get, the better we are at the exams and in life in general. Pls join me at My DEN.
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683

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.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Doubt in stateful session bean
 
Similar Threads
How to imbed servlet in JSF
Issues with Oracle connection/statement when accessing through JDBC
How to add new text boxes and check boxes dynamically when clicking on button in JSF
Take input from <h:inputText> in rich <modalPanel>
Navigation does not work