-->
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: Should save/merge generate sql if session is not flushed?
PostPosted: Wed Jun 22, 2011 5:19 am 
Newbie

Joined: Wed Apr 08, 2009 6:45 am
Posts: 5
Hello,

Should save or merge generate an insert statement if the session is not flushed?

I realise that it would have to if you were using a sql server identity column (because it needs to go straight to the database to get it), but I thought it wouldn't if you were using a different type of primary key such as a UUID?

cheers,
Jordan.


Top
 Profile  
 
 Post subject: Re: Should save/merge generate sql if session is not flushed?
PostPosted: Mon Jun 27, 2011 11:36 am 
Newbie

Joined: Wed Apr 08, 2009 6:45 am
Posts: 5
Anyone know this? I can't find info in any docs.

My understanding is that SQL should be generated when the session is flushed. (Either explicitly by calling session.flush(), or when a transaction commits and the flush mode is set to 'Commit' or 'Auto').

Is this true? Or would save/merge cause SQL to be generated immediately?

cheers,
Jordan.


Top
 Profile  
 
 Post subject: Re: Should save/merge generate sql if session is not flushed?
PostPosted: Thu Jun 30, 2011 12:55 pm 
Newbie

Joined: Thu Apr 21, 2011 8:59 am
Posts: 14
Hi Jordan,
A flush causes the sql statements to be prepared. And these get executed at the transaction commit time.
So, in case where flush() is manually invoked after a save()/update(), the sql gets generated at that time itself and they get executed at tx commit time.
However if a flush() is not manually called, the sql gets both generated and executed at the tx commit time itself(Happens only if the flush mode is auto or commit).
The only scenario where the sql does not get generated and save()/update() will not work will be if flush mode is specified as Manual and the flush() is not invoked manually.

Hope this helps,

_________________
Lokesh, C
( SCBCD 5, CCENT, SCJP 5 )


Top
 Profile  
 
 Post subject: Re: Should save/merge generate sql if session is not flushed?
PostPosted: Mon Jul 18, 2011 10:56 am 
Newbie

Joined: Wed Apr 08, 2009 6:45 am
Posts: 5
lokeshc wrote:
Hi Jordan,
A flush causes the sql statements to be prepared. And these get executed at the transaction commit time.
So, in case where flush() is manually invoked after a save()/update(), the sql gets generated at that time itself and they get executed at tx commit time.
However if a flush() is not manually called, the sql gets both generated and executed at the tx commit time itself(Happens only if the flush mode is auto or commit).
The only scenario where the sql does not get generated and save()/update() will not work will be if flush mode is specified as Manual and the flush() is not invoked manually.
Hope this helps,


Hi,

Yes - what you have written is exactly what I would expect.

However, this is not the behaviour I am seeing in a .NET Nhibernate application. I am seeing SQL generated when I call merge despite the fact the the flush mode is set the 'NEVER' and flush is not invoked manually. I have not had time to test how java hibernate behaves - that is why I thought I would ask here first. When I get time I'll write a test.

regards,
Jordan


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.