• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Txn not automatically rolling back after RemoteException

 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
DAOs throw SQLException which is system exception.
 
somkiat puisungnoen
Ranch Hand
Posts: 1312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 8945
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Gul:
DAOs throw SQLException which is system exception.



SQLException is not a system exception.
 
Ranch Hand
Posts: 1209
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you got sqlexception in Tx2, you must rollback TX in Tx2 . But not Aauto-Rollback in related Tx.
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 354
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A System Exception is actually a RuntimeException.
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic