-->
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.  [ 2 posts ] 
Author Message
 Post subject: Hibernate Session management after exception
PostPosted: Wed Jun 10, 2009 4:05 pm 
Newbie

Joined: Mon Oct 11, 2004 5:06 pm
Posts: 4
Hello,
I'm developing an application and am using the session-per-request pattern. During the request process I need to commit the transaction, and thus flush the hibernate session, at various points (this is being accomplished by the Spring framework and AOP).

A problem arises when an exception is thrown during a flush operation. At this point I am aware that the session should be "discarded"; however, after looking at the Spring code I do not see that they are doing this for me, and it looks like it would be a heroic feat to alter the code to actually discard the old session and insert a new one at the necessary points. I have found a solution that will allow me to run a session.clear() at the appropriate points.

So...my question is: After an exception on a session.flush() operation, will a session.clear() be sufficient to guard against any invalid hibernate session state and/or data reads/writes/commits? If not, it's back to the drawing board...

Thanks in advance for any help!
Dave Wolff


Top
 Profile  
 
 Post subject: Re: Hibernate Session management after exception
PostPosted: Wed Jun 10, 2009 5:02 pm 
Newbie

Joined: Mon Oct 11, 2004 5:06 pm
Posts: 4
Well, I actually realized that there's a snippet of code in a finally block in Spring's HibernateTransactionManager that I had missed that is doing essentially the same thing as I thought I needed to add in. So that means that my addition is unnecessary, but if possible I would still like some clarification on whether a clear() is sufficient to avoid any invalid session state and invalid reads/writes to the database.

Thanks again,
Dave


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.