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: Setting FlushMode to Commit globally...good or bad idea?
PostPosted: Thu Nov 02, 2006 3:00 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Hi,

I am considering setting the FlushMode on my session to Commit globally so that I don't get any unexpected flushes occuring midway through a transaction.

What is the consensus on this...are other people doing likewise or using a FlushMode of Auto?

Thanks,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 3:29 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Disclaimer: I'm a Hibernate user, so take my advice with caution. I was already a Hibernate user in v2(v3 now), and NHibernate is said to be a port for .Net of the v2.

I guess most of the time, you should let the FlushMode.AUTO selected. There's some particular cases where you should use ALWAYS or NEVER (long conversations, disconnecting session between each step of a process for example).

FlushMode.AUTO will certainly act as you'd like : only sending queries when committing OR when a new query is detected to be "result-dependent" of another one which has not been sent yet, so as to have kind of more data integrity.

In NHibernate, what are the possible values of FlushMode?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 3:36 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
Possible values are Auto, Commit and Never.

I was using Auto originally, but found that a call to retrieve an object from the Session could trigger the DB updates of the objects that I had been updating as part of the transaction, even though I had not finished my transaction yet.

Setting the FlushMode to Commit seemed to fix the probelm but I was not sure what the repurcussions were for doing that.

Cheers,

Jason


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 19, 2006 4:44 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Well, even if the queries are sent to the DB, you shouldn't care. In fact, you're still in a tx context, so even if Hibernate sends an update on a table, a final rollback would unmake it...

Nobody can see the results of these updates if the tx is in a common transaction isolation mode.

Why don't you want these updates not to be flushed? I guess Hibernate is doing it because it thought it could affect the object you're trying to retrieve.

To sum up, there's no problem to use the FlushMode.COMMIT, but then you will have to call refresh() by yourself on objects you know to be dirty.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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.