-->
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.  [ 6 posts ] 
Author Message
 Post subject: Does session.flush() commit the current transaction?
PostPosted: Mon Jun 06, 2005 12:45 pm 
Senior
Senior

Joined: Tue Mar 02, 2004 6:17 pm
Posts: 151
If I session.flush() in the middle of a transaction and transaction.rollback() later on, do my changes get undone all the way to the beginning of the transaction or only up to the last Session.flush()?

Thank you,
Gili


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 06, 2005 9:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
flush will execute any outstanding SQL operations only. No transaction state changes.


Top
 Profile  
 
 Post subject: Reply not very clear
PostPosted: Fri Jul 29, 2005 1:21 pm 
Newbie

Joined: Tue Apr 19, 2005 4:32 pm
Posts: 14
Quote:
flush will execute any outstanding SQL operations only. No transaction state changes.

I'm sorry, but the reply above is not very clear to me.

If I perform a session.flush() which causes SQL for an earlier session.save() to get executed. And then I explicitely rollback the transaction, will the SQL executed on flush also be rolled back?

In other words ..
Code:
Session s = sessionFactory.openSession();
Transaction tx = s.beginTransaction();
s.save(objA);
s.flush();
tx.rollback();
s.close();

Will 'objA' get saved to the database?

Also, if instead of rolling back the transaction, I simply close my session without committing, will the SQL executed on flush be rolled back?

Again ..
Code:
Session s = sessionFactory.openSession();
Transaction tx = s.beginTransaction();
s.save(objA);
s.flush();
s.close();  // close session without committing or rolling back

Will 'objA' get saved to the database?

Thanks, Rishabh


Top
 Profile  
 
 Post subject: Re: Reply not very clear
PostPosted: Fri Jul 29, 2005 2:20 pm 
Senior
Senior

Joined: Sat Jul 17, 2004 5:16 pm
Posts: 143
skewed wrote:

If I perform a session.flush() which causes SQL for an earlier session.save() to get executed. And then I explicitely rollback the transaction, will the SQL executed on flush also be rolled back?



It makes the SQL go across to the DB. So if your DB is setup so SQL will be rolled back (e.g. Oracle), then yes, all will be rolled back.

Quote:
Also, if instead of rolling back the transaction, I simply close my session without committing, will the SQL executed on flush be rolled back?


I dont know the defaults, but I could see if auto-commit mode was set to true on the connection (which is the default), then it could very well happen. Set that to false in the DB connection or in your pool, then probably it will not. You have all the sample code, so give it a try.

Chris


Top
 Profile  
 
 Post subject: Re: Does session.flush() commit the current transaction?
PostPosted: Mon Feb 11, 2013 3:52 am 
Newbie

Joined: Mon Feb 11, 2013 3:46 am
Posts: 1
session.flush()

just synchronizing with database (fetching latest data from DB), not updating DB with latest changes to POJO.

is this correct behaviour?

cris


Top
 Profile  
 
 Post subject: Re: Does session.flush() commit the current transaction?
PostPosted: Tue Feb 12, 2013 6:05 am 
Beginner
Beginner

Joined: Wed Feb 06, 2013 2:43 am
Posts: 46
This is from the hibernate documents :
Except when you explicitly flush(), there are absolutely no guarantees about when the Session executes the JDBC calls, only the order in which they are executed.

However, Hibernate does guarantee that the Query.list(..) will never return stale or incorrect data.


So the thing is after the flush and before the commit, if you access DB directly then you will not see the changes from another session.

The flush is just synchronization with the db and then you need to commit or clear the session to see the changes.
And if you do just commit .It automatically flushes and you can see your changes from another session too.

_________________
Thanks,
Ajit Singh
ajits@mindfiresolutions.com
www.mindfiresolutions.com


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