• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Txn not automatically rolling back after RemoteException

 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In EJB,

Transaction are automatically rolled back with system exception, but not with application exception.
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
DAOs throw SQLException which is system exception.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why you use DAO with CMP Entity Bean ?
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Gul:
DAOs throw SQLException which is system exception.


SQLException is not a system exception.
 
Karthik Guru
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you got sqlexception in Tx2, you must rollback TX in Tx2 . But not Aauto-Rollback in related Tx.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Gul Khan
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 354
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A System Exception is actually a RuntimeException.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic