File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and other Java EE Technologies and the fly likes Transaction Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Transaction Problem" Watch "Transaction Problem" New topic
Author

Transaction Problem

Venkatesh Rangamani
Ranch Hand

Joined: Aug 24, 2005
Posts: 31
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
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Is this a container managed transaction?

What is the transaction attribute of the EJB?


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Venkatesh Rangamani
Ranch Hand

Joined: Aug 24, 2005
Posts: 31
Yes it was a CMT bean.
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

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 ]

apigee, a better way to API!
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
You need to answer the question I asked:

What is the transaction attribute of the EJB?
Sunil Dixit
Ranch Hand

Joined: Sep 22, 2005
Posts: 46
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
Amit M Tank
Ranch Hand

Joined: Mar 28, 2004
Posts: 257
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.


Amit Tank
Linked In
Sunil Dixit
Ranch Hand

Joined: Sep 22, 2005
Posts: 46
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: Transaction Problem