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: Correct time to call Session.BeginTransaction?
PostPosted: Tue Dec 19, 2006 2:26 am 
Senior
Senior

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

The examples in the NH documentation show the transaction being started before any object properties are updated. Is this a mandatory requirement or is it acceptable to load objects, update properties and then call BeginTransaction followed by Commit to update all the changed objects as part of a single transaction?

My understanding is that the BeginTransaction really acts as a wrapper for an ADO transaction so it would seem that there is no need to start the NH transaction until just before you want to commit all of the changes made in the session...is that right or are there other things that occur as part of the BeginTransaction call?

Thanks,

Jason


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

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I would recommend you to start the transaction before doing any save() or update(). In fact, it would not be very correct if some flush (i.e. a query :-/) occurred although no tx was started.

If you use the persist() method instead of save(), one guaranty is that no query will be issued until there's a tx context (cf. Java Persistence with Hibernate book).

UPDATE : I just noticed I was in the NHibernate forum, not the hibernate one. So I guess my second paragraph does not apply, but still the first one.

_________________
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:16 am 
Senior
Senior

Joined: Sat Sep 03, 2005 12:54 am
Posts: 139
OK...I am starting the transaction before calling Save or Update so it sounds like things are OK.

Yes, I have already stumbled across the problem of unexpected flushing that commits half finished changes to the DB and I have set Session.FlushMode = Commit globally in the application to prevent this from happening.

However, I never did get a response to my other post about the FlushMode...do you have any thoughts about this: http://forum.hibernate.org/viewtopic.php?t=966735&highlight=

Thanks for your help.

Jason


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.