-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: clearing an exception
PostPosted: Wed Apr 26, 2006 7:02 pm 
Newbie

Joined: Fri Dec 09, 2005 2:22 pm
Posts: 16
Hello,

I use NH to access an oracle database. Sometimes I get an oracle exception when inserting a row due to a constraint violation. I use a transaction and rollback it in case of an exception.
The problem is that from that moment my last insert remains in the session insertion list and I cant execute any other query without having the same exception. If I call session.clear() it works again but I lose all my entities in the session.
Is there any efficient way to clear the session state after an exception ?

thank you
Anthony


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 26, 2006 10:28 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No. It is an hibernate requirement: when an HibernateException is thrown, you must discard or reset your session. There is no alternative.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 27, 2006 2:59 am 
Regular
Regular

Joined: Tue Mar 15, 2005 12:38 pm
Posts: 73
Location: Bucharest
I may though give you an advice... In my opinion although the scenario is not common it is though expected... You can evict the objects that caused the exception from the session using session.Evict or even session.Clear to clear-out the session.

Of course that this is not a good idea for any kind of exception, you should apply this only in the case of an ADO exception and if the items being saved are not many (in complex situations I'm not sure of what entity caused the exception and what to evict).

_________________
Dragos


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.