• Post Reply Bookmark Topic Watch Topic
  • New Topic

Urgent::Not able to rollback UserTransaction  RSS feed

 
Raj Sikka
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
...
}
 
I Wayan Saryada
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Hi ,
I was using utx.begin() in my code.
thanks,
Srikanth
 
Sameer Boddun
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
U should move ur transaction related code to ejbCreate method.
 
Dana Hanna
Ranch Hand
Posts: 227
  • Mark post as helpful
  • send pies
  • 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...
 
Chris Mathews
Ranch Hand
Posts: 2712
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!