-->
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: Insert occurs before flush
PostPosted: Sat Jan 05, 2008 1:28 pm 
Beginner
Beginner

Joined: Tue Sep 04, 2007 12:36 pm
Posts: 23
Hi this is a general question about NHibernate 1.2...

I want to save an object, but I do not want the INSERT command to occur before the session.Flush()...


I tried setting the Session.FlushMode to FlushMode.Never, but it still onvokes an INSERT command immediately.

how can I control this?

_________________
^^If this post helped you, make sure to rate it Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 06, 2008 4:42 am 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Are you concerned because you see an SQL statement in the debug or console? That doesn't necessarily mean that the SQL statement has been actually committed to the database.

Do you see an actual record inserted in the table?

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 06, 2008 12:10 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
If you're using database generated identifiers an insert will occur before you call flush because NHibernate needs to get the Id of the entity from the database. If you want to avoid this you can use NHibernate or user generated identifiers, however it shouldn't matter as long as you have a transaction that you can roll back.

Cheers,

Symon.


Top
 Profile  
 
 Post subject: Re: Insert occurs before flush
PostPosted: Mon Jan 07, 2008 5:58 pm 
Beginner
Beginner

Joined: Tue Sep 04, 2007 12:36 pm
Posts: 23
PeteWeissbrod wrote:
Hi this is a general question about NHibernate 1.2...

I want to save an object, but I do not want the INSERT command to occur before the session.Flush()...


I tried setting the Session.FlushMode to FlushMode.Never, but it still onvokes an INSERT command immediately.

how can I control this?


These are both helpful clues.

#1. if you use <generator class="identity" />, an INSERT command will happen immediately after the Save(..) call, this is by design, because the ID is assigned to the SCOPE_IDENTITY.

#2. you should not care when the insert occurs... If your session is properly wrapped inside of a transaction, the insert is not committed until the transaction is committed.


This alone is a good reason to use transactions with ANY session interaction, it gives you a higher degree of control over your database interactivity.

thanks guys!

_________________
^^If this post helped you, make sure to rate it Thanks!


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.