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.  [ 4 posts ] 
Author Message
 Post subject: Flush() commits rolled back transactions
PostPosted: Fri Nov 03, 2006 2:23 am 
Newbie

Joined: Fri Nov 03, 2006 2:05 am
Posts: 3
Hi. I'm hoping someone here can confirm this is a bug in NHibernate (v. 1.0.2):

If flush() is called after ITransaction.Rollback(), the data in the transaction is NOT rolled back unless a flush has already been executed.

To duplicate:

Code:
   
trans = session.BeginTransaction();
MyObj root = session.Load(typeof(MyObj), id);
MyObj.Name ="Changed Value";
trans.Rollback();
session.Flush();


The change is saved! This means that I need to be careful not to invoke any code that might trigger a flush in any finally clause in my application. Seems like a bug.

Note that in contrast to the above, if a flush occurs prior to the rollback, the transaction begins in the DB like you'd expect. In other words, the following code works fine:

Code:
trans = session.BeginTransaction();
MyObj root = session.Load(typeof(MyObj), id);
MyObj.Name ="Changed Value";
session.Flush();
trans.Rollback();
session.Flush();



It seems clear that at least one of these two behaviors is incorrect. Can someone let me know how to resolve this?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 4:20 am 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
No, that is the expected behavior, I am afraid.

The issue here is that transaction rollback is not going to modify the state of an object in memory.
When Flush() is called later on, it understand that there are unsaved changes and attempts to save them.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 12:46 pm 
Newbie

Joined: Fri Nov 03, 2006 2:05 am
Posts: 3
Hmmm... currently my architecture flushes before a request ends. Is this a mistake?

What is the recommended way to handle exceptions in a transaction? Rollback and close the session immediately?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 03, 2006 1:59 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
You could try evicting the offending entities.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.