| Author |
Txn not automatically rolling back after RemoteException
|
Gul Khan
Ranch Hand
Joined: Sep 03, 2003
Posts: 173
|
|
Hi, I have an EJB calling a DAO. A connection object is passed to the DAO. the DAO is further calling other DAOs sharing the same connection. The problem that I am having is that if some DAO in the chain throws an SQLException the earlier DAOs txn is not rolled back. There is no commit inside the DAOs. I am using CMT EJB in weblogic 8.1. Thanks for any help.
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
In EJB, Transaction are automatically rolled back with system exception, but not with application exception.
|
SCJA,SCJP,SCWCD,SCBCD,SCEA I
Java Developer, Thailand
|
 |
Gul Khan
Ranch Hand
Joined: Sep 03, 2003
Posts: 173
|
|
|
DAOs throw SQLException which is system exception.
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
|
Why you use DAO with CMP Entity Bean ?
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
Exception in EJB 1. System exception - RemoteException - EJBException - IllegalStateException - TransactionRequiredException - NoSuchObjectException - ArrayIndexOutOfBoundException - NullPointerException - RuntimeException 2. Application Exception - CreateException - RemoveException - FinderException - ObjectNotFoundException - DuplicateKeyException - YourException
|
 |
Pradeep bhatt
Ranch Hand
Joined: Feb 27, 2002
Posts: 8876
|
|
Originally posted by Gul: DAOs throw SQLException which is system exception.
SQLException is not a system exception.
|
Groovy
|
 |
Karthik Guru
Ranch Hand
Joined: Mar 06, 2001
Posts: 1209
|
|
Originally posted by somkiat puisungnoen: Why you use DAO with CMP Entity Bean ?
I thought he said CMT. not CMP. He is probaly referring to a session bean facade i guess. ------------------ Anyways make sure you use txdatasource while configuring it. Catch the SQLException in your session bean and do setRollbackOnly on the sesion context.
|
 |
Gul Khan
Ranch Hand
Joined: Sep 03, 2003
Posts: 173
|
|
Yes EJB is a session bean, a facade to DAO. SQLException is not a system exception? EJB client receives a RemoteException when SQLException is thrown from DAO!!! Thanks for the replies. GUL
|
 |
somkiat puisungnoen
Ranch Hand
Joined: Jul 04, 2003
Posts: 1312
|
|
|
When you got sqlexception in Tx2, you must rollback TX in Tx2 . But not Aauto-Rollback in related Tx.
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
Gul, Welcome to JavaRanch! We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy. Thanks Pardner! Hope to see you 'round the Ranch!
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Gul Khan
Ranch Hand
Joined: Sep 03, 2003
Posts: 173
|
|
Originally posted by somkiat puisungnoen: When you got sqlexception in Tx2, you must rollback TX in Tx2 . But not Aauto-Rollback in related Tx.
I dont understand what you mean by that.
|
 |
Abhinav Srivastava
Ranch Hand
Joined: Nov 19, 2002
Posts: 345
|
|
|
A System Exception is actually a RuntimeException.
|
 |
David Harkness
Ranch Hand
Joined: Aug 07, 2003
Posts: 1646
|
|
|
You have two choices here. If you want to continue having RemoteException thrown, or you want to throw your own application exception (not a subclass of RuntimeException), you need to tell the container to rollback the transaction. I have the following method in my base EJB:Your other option is to throw any exception that extends RuntimeException or one of its subclasses -- a system exception. In that case the container will rollback the transaction.
|
 |
 |
|
|
subject: Txn not automatically rolling back after RemoteException
|
|
|