Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

TransactionAttribute REQUIRED automatically rolls back on a RuntimeException  RSS feed

 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ,

While going through tutorials of Transaction Attributes on EJB .

I have read that REQUIRED automatically rolls back on a RuntimeException .

I have a query here , Please tell me When a CheckedException Arises , how can we manually rollback the Transaction ??

Thanks in advance .
 
Manuel Alberto Quero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ravi,

You can tell the EJB container to rollback like follows:

try {
//throw your ApplicationException
}
catch (ApplicationException e) {
sessionCtx.setRollbackOnly(); //You need to inject SessionContext by using @Resource annotation
}

Another way would be to indicate it annotating your Application Exception with @javax.ejb.ApplicationException (rollback=true) or in ejb-jar.xml:

<application-exception>
<exception-class>YourApplicationException</exception-class>
<rollback>true</rollback>
</application-exception>

Hope it helps,

Manuel
 
Ravi Kiran Va
Ranch Hand
Posts: 2234
Eclipse IDE Firefox Browser Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Alberto.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!