Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Transaction roll back in session bean

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's stateless cmp session bean, ejb 2.1 in jboss 4.0.5GA
 
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic