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

Transaction roll back in session bean

 
Michal Glowacki
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I've a session bean to compute and create complex report. It stores data in 3 tables, and should be completely rolled back when any exception occurs. It's sth like this:

public void createReport() {
reportId = reportEntityBean.create(...).getReportId();

for(...)
createSubReport(reportId, ...); /* invokes some calculations and subreportEntityBean.create(reportId, ...); */

for(...)
createReportItem(reportId, ...); /* invokes some calculations and reportItemEntityBean.create(reportId, ...); */

checkIsValid();
}

Ok, this code if everything is ok, should create entities in 3 tables. But I want also everything to be rolledback if any exception in this method or methods invoked by it occurs. For example, if report entity is already create and exception in subreportEntintyBean.create method is raised, I want to remove created report. Unfortunately it's not working as expected. In ejb-jar.xml I have set attributes of the methods:

createReport as Required
createSubReport, createReportItem, checkIsValid as Required (also tried with Mandatory)


please help.
 
Michal Glowacki
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's stateless cmp session bean, ejb 2.1 in jboss 4.0.5GA
 
Shivani Chandna
Ranch Hand
Posts: 380
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If one throws an application exception from the method with defined attribute of rollback=true then rollback takes place (EJB 3.0 )
OR
Call the method SessionContext / setRollbackOnly(). This flags that the method transaction should be rolled back.


Could you please check if this works with EJB 2.1 for your case as well?

- Shivani
 
Michal Glowacki
Ranch Hand
Posts: 114
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I enclosed all operations in method createReport into try catch block, and I invoke setRollbackOnly() in each catch block. Unfortunately transaction is not rolled back.
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your JDBC connection. If you get a JDBC connection from a plain DataSource or directly from the JDBC driver, it will not participate in the EJB container transaction.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic