Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Urgent::Not able to rollback UserTransaction

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I am not able to rollback the UserTransaction.
Pls help me out.
My UserTransaction starts in HelperBean.
HelperBean calls a SessionBean and SessionBean calls EJBs create method.
Problem is ..
I need to do some operations in SessionBean after calling the EJBs create method.
If i get any errors during this i need to throw error to the calling HelperBean and
need to rollback all the operations including EJBs create method.
rollback() statement is getting executed in my Helper bean but it is not actually rolling back the create operation.
I am able to see the entry created by 'create' method,of my EJB,in the database.
I just want to rollback the create operation.
I am using DataSource for getting the connection.
Pls suggest me what can be the solution for this ?
Following is the sample code i am using .
---------------------------------------------------------
HelperBean
{
ctx=getInitialContext();
utx=(UserTransaction)ctx.lookup("javax.transaction.UserTransaction");
//do Session lookup and all.
//in case of success
utx.commit();
//in case of any exceptions
utx.rollback();
}
SessionBean
{
//do some operations
...
//call create method of entity bean
entityBean.create();

//do some operations
//throw error in case of any violation during these operations
...
}
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I think you forget to start your transaction.
You should call utx.begin() to start the transaction after you had looked-up the user transaction object.
regards,
Wayan
 
Raj Sikka
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I was using utx.begin() in my code.
thanks,
Srikanth
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
U should move ur transaction related code to ejbCreate method.
 
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Sameer Boddun:
U should move ur transaction related code to ejbCreate method.


I disagree - In this case he's trying to manage a remote transaction.
No answer for you (SORRY!) but just disputing the prior...
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two questions:
1) What are the transactional settings for your Session and Entity Bean? They should be either Supports, Mandatory, or Requires depending on your application's needs.
2)What Application Server are you using? If it is WebLogic then make sure you are using a TxDatasource instead of a plain ole Datasource.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic