*
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes question about BMT calling CMT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "question about BMT calling CMT" Watch "question about BMT calling CMT" New topic
Author

question about BMT calling CMT

vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
Question:

QUESTION 122
Given:
9. @Stateful
10. TransactionManagement(TransactionManagementType.BEAN)
11. public class FacadeBean implements Fa�ade {
12. @EJB Business business; @Resource SessionContext ctx;
13. public void startstuff() throws Exception{
14. ctx.getUserTransaction.begin();
15. business.doA();
16. business.doB();
17. }
18. public void endStuff() throws Exception {
19. ctx.getUserTransaction.commit();}}
11. @Stateless
12. public class BusinessBean implements Business {
13. @Resource SessionContext ctx;
14. public void doA() { ctx.setRollbackOnly(); }
15. @TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
16. public void doB() { }

A client calls startstuff and endstuff subsequently. Assuming NO other transaction-related
metadata, which two statements are correct? (Choose two.)
A. Method doB is never called.
B. The transaction in method doB is committed.
C. The transaction in method doB is rolled back.
D. An exception is thrown when calling method endStuff.
E. An exception is thrown when calling method startStuff.

given anwser is B,D.
I am wondering what happed when doA() was called?context transaction is BMT, but ctx.setRollbackOnly() is only working for CMT,does DoA() join BMT,or it will create new CMT,whatever happed,transaction was marked rollback,how DoB() was called?
anybody clear this for me,thanks advance!


SCJP 5.0<br />SCWCD1.4<br />SCBCD5
Tushar Roy
Greenhorn

Joined: Mar 26, 2008
Posts: 29
doA() starts a CMT (REQUIRED) transaction which joins BMT transaction of startstuff...doA only sets the transaction for rollback...This does not mean transaction is actually rolledback at that point....Now doB() is called and it has REQUIRES_NEW attribute so its transaction suspends the transaction of startstuff and commits successfully....Now when we try to commit the transaction in endStuff method TransactionRolledBackException is thrown from that method since the transaction was already marked for rollback in doA()....


Tushar<br /> <br />SCJP 5 (95%)<br />SCWCD 1.4 (92%)<br />SCBCD 5 (93%)
vitesse wei
Ranch Hand

Joined: Sep 07, 2007
Posts: 100
thanks,Tushar,that helps.
 
Consider Paul's rocket mass heater.
 
subject: question about BMT calling CMT