-->
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: Rollback does not flush the session, intentionally?
PostPosted: Fri Feb 09, 2007 5:48 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 5:33 pm
Posts: 28
Location: Chicago, IL
I just ran into an interesting situation today. We would start a session and transaction. Part of this transaction involved creating and modifying a Library. Eventually, the transaction would get rolled back. and the Library removed from the database.

Immediately after that, we began a new transaction to create a new user. When we committed the transaction with the user, we received StaleStateExceptions.

It turns out that what was happening was that when we rolled back the Library transaction, the Library update commands were still queued up in the batcher and were not removed. The next time flush was executed (on the User commit), the batched update statements were being run on a Library id that was taken out of the database during the previous rollback.

Now I realize that the easy fix for all of this is to simply flush the session before the rollback. However, I was wondering if the batcher and session were intentionally created this way. Leaving the commands in the batcher after the transaction is rolled back seems like leaving some cleanup undone. And making systems flush commands that could simply be thrown out seems like a waste of cycles.

If someone has looked at this before and it is too difficult to change, I completely understand the "Just call flush" response. But as a relative newbie, I was a little supprised when ending transactions one way flushed the session and ending them another didn't. Or is there a reason to leave the commands in the session that I'm just not aware of?

Thanks

_________________
Chuck

Not in the face! Not in the face!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 09, 2007 6:39 pm 
Regular
Regular

Joined: Mon Mar 20, 2006 10:49 pm
Posts: 59
Correct practice is to discard the session after an error, i.e., close it without flushing.

_________________
Mike Abraham


Top
 Profile  
 
 Post subject: Any other ideas?
PostPosted: Fri Feb 09, 2007 7:01 pm 
Beginner
Beginner

Joined: Wed Nov 29, 2006 5:33 pm
Posts: 28
Location: Chicago, IL
I will definately have to keep that in mind. Though I am not going to try that out first because we are using the one session per http request approach of managing sessions. It's worked great so far and I dislike the idea of needing to juggle the sessions during a request. Also, after discarding the session, I will need to reattach all of the business objects currently referenced to a new session. Not that it couldn't be done, but it would be a bunch of work I would rather avoid if at all possible.

I found Session.Clear which clears all of the batched, unsent commands. This would be nice if Clear didn't also evict all of the entities which gets me back to reattaching all of my instances.

Edit --- Ah and save or update takes care of the reattaching for me.

Thanks for the kick in thr right direction.

_________________
Chuck

Not in the face! Not in the face!


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.