-->
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: Why both flush() and commit() required?
PostPosted: Thu Jun 23, 2005 10:36 pm 
Beginner
Beginner

Joined: Thu Jun 23, 2005 10:23 pm
Posts: 22
Weblogic 8.1, EJB Stateless Session Bean, for transaction marked required, I can only get objects to persist successfully if I do:

session.beginTransaction();
session.save(obj);
session.flush();
tx.commit();

My understanding, from reading several documentation, is that only flush is required and tx.commit() is NOT needed. Any ideas why it will only work if both flush/commit are used? When doing only flush OR commit alone, hibernate successfully creates object with new generated id, but nothing is saved to DB when done with transaction - and no errors are returned.

Thanks in advance for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 23, 2005 10:49 pm 
Senior
Senior

Joined: Thu May 12, 2005 11:40 pm
Posts: 125
Location: Canada
Are you sure you're closing your session properly?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 9:19 am 
Beginner
Beginner

Joined: Thu Jun 23, 2005 10:23 pm
Posts: 22
Yes, I am closing the session properly with session.close().


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 1:18 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
You've got it backwards, flush() will be called on commit().

From section 12.2.1 of the reference docs:

You don't have to flush() the Session explicitly - the call to commit() automatically triggers the synchronization.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 1:24 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Ok, not sure what I read but it seems that my above post isn't quite the answer you were looking for so you don't quite have it backwards ;)

In your above example, I would expect if you used both flush() and commit() OR if you used commit() the data would be persisted. Are you changing the flush mode on your session?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 24, 2005 2:09 pm 
Beginner
Beginner

Joined: Thu Jun 23, 2005 10:23 pm
Posts: 22
That is also my understanding, that commit() should take care of persisting without the need to explicitly call flush() since that is what commit() will do.

I also believe that commit() is not necessary since I am already in a transaction managed environment, so if I don't want to use Transactions explicitly, I don't have to, but I found that using flush alone doesn't work for me either.

I am not changing the flush mode, but I will look into that to see if its something related to the problem. My goal is to not have to use both, but one or the other only.

Thanks for the info.


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.