• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Transaction Problem

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranchers,
I just wrote an Remote Steteful Session EJB as follows:

try{
con=getJDBCConnection();
ps =con.prepareStatement("UPDATE emp set ename='$'||ename");
int res = ps.executeUpdate();
if(res>0){
System.out.println("SUCCESS....");
}
else{
System.out.println("FAILURE....");
}
String str = null;
str.charAt(i); //Wantedly threw a NullPointerException
}catch(RuntimeException e){
System.out.println("RollBack Status in RemoteEJB is " + sc.getRollbackOnly() + System.currentTimeMillis());
throw e;
} catch (SQLException e) {
System.out.println("RollBack Status in RemoteEJB in SQLExcp is " + sc.getRollbackOnly());
e.printStackTrace();
throw new EJBException(e);
}


I basically did a DB Update and then threw a NullPointerException. The Client received the RemoteException. But my doubt is that the transaction was not rolledback as the SOP in the catch shows getrollbackonly as FALSE. I saw the below exception in console

javax.transaction.SystemException: Heuristic hazard: (weblogic.jdbc.wrapper.JTSX
AResourceImpl, HeuristicHazard, (javax.transaction.xa.XAException: ORA-01013: us
er requested cancel of current operation



And i also found that the EJB has Locked the row in the table, i manually killed the session. So this means the update has not rolledback and the transaction is hanging in the middle. Why is not the transaction olledback after the bean threw a SystemException?

Thanks
Venkat
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this a container managed transaction?

What is the transaction attribute of the EJB?
 
Venkatesh Rangamani
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes it was a CMT bean.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My two cents.
Your SOP will never give the tx status as rollback as the transaction status is set to rollback if the runtime exception is thrown by the EJB method.
So, when your ejb's method is completed (by throwing an exception), then only it will be rolled back and not at the point you catch the exception in your code.
How many resources are participating in this transaction?
Just check if this article helps you.
[ June 18, 2007: Message edited by: Nitesh Kant ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to answer the question I asked:

What is the transaction attribute of the EJB?
 
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Think roger is right... and the reason is if you are using BMT than this case can occurr... coz you have begin the Tx but not rollbacked yet.... that may be the reason why EJB has Locked the row in the table.
And as far as your print a message is concern ... plzz check your log4j.xml file.

Sunil
 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Nitesh Kant, if the transaction was required or requiresnew or atleast supported and is invoked in a transation then the container will rollback the transaction when it handles the runtime exception.
 
Sunil Dixit
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Amit,
Just want to bring the fact if you are not using BMT than by default Required Tx attribute is being imposed on beans.

Sunil Dixit
 
I am displeased. You are no longer allowed to read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic