Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need understanding on Handling of setRollbackOnly invoked from methods with transaction attribute

 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Source:EJB 3.1 Specfication
13.6.2.8 Handling of setRollbackOnly Method


The container must handle the EJBContext.setRollbackOnlymethod invoked from a business
method executing with the REQUIRED, REQUIRES_NEW, or MANDATORY transaction attribute as follows:

1.The container must ensure that the transaction will never commit. Typically, the container
instructs the transaction manager to mark the transaction for rollback.

2.If the container initiated the transaction immediately before dispatching the business method to
the instance (as opposed to the transaction being inherited from the caller), the container must
note that the instance has invoked the setRollbackOnlymethod. When the business
method invocation completes, the container must roll back rather than commit the transaction.
If the business method has returned normally or with an application exception, the container
must pass the method result or the application exception to the client after the container per-formed the rollback.


Please let me know if my understanding for the statement 2 mentioned above is correct .

1.As stated in the first sentence "container initiated the transaction immediately before dispatching the business method to the instance"

1.Understanding:Does this line means that "container is starting a new transaction as opposed to be inherited from caller" ?

2.As stated in the first sentence"If the business method has returned normally or with an application exception, the container must pass the method result or the application exception to the client after the container performed the rollback "

2.Understanding:If the Business method executed normally,then container passes the method result to caller.Here,result cannot be part of transaction Because if it is a part of transaction then the result will not be obtained as the transaction was rolled-backed.
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2418
95
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohit,

1.Understanding: Does this line means that "container is starting a new transaction as opposed to be inherited from caller" ?

Yes, your understanding is correct.

Understanding:If the Business method executed normally,then container passes the method result to caller.Here,result cannot be part of transaction Because if it is a part of transaction then the result will not be obtained as the transaction was rolled-backed.

Yes, correct. As you notice the caller won't be affected by rolling back the transaction on the called instance as the caller wasn't involved in the transaction from the start.

Regards,
Frits
 
Mohit G Gupta
Ranch Hand
Posts: 634
Chrome Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic