Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

question about BMT calling CMT

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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()....
 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks,Tushar,that helps.
 
Grow a forest with seedballs and this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic