-->
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: Difference in commiting data and transactions?
PostPosted: Mon Dec 06, 2004 2:29 pm 
Beginner
Beginner

Joined: Fri Oct 01, 2004 7:13 am
Posts: 20
Hibernate version:2.13

We are using some code that is explicitly flushing - which we have seen takes a while - which makes sense.

We are not currently using a transaction in the instance, but instead

//session.flush(); --This taking a while for a relatively simple operation
session.connection().commit();

However when we access the db from another source we cannot see the records, but this could be that Hibernate has not flushed it's data yet.

Can someone explain the difference between commiting as above and using a transaction?

Transaction trans = session.beginTransaction();
....
trans.commit();


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 6:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Flush tell hibernate to send any unit-of-work operations to the database, eg, execute outstanding SQL operations. Obviously, the flush needs to be performed (where Hibernate will automatically perform a flush in various situations) within the transaction boundary. The transaction can then be commited or rolledback depending again on success or otherwise or the use case. Don't use the JDBC driver directly for the transaction commit as it could cause the transaction manager to get out of sync. The Hibernate documentation clearly defines the transaction framework you should apply in your code, eg,

Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}


The above code is all that you need. The tx.commit will perform the flush for you.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 07, 2004 7:13 am 
Beginner
Beginner

Joined: Fri Oct 01, 2004 7:13 am
Posts: 20
Thanks David for confirming that.

Will use the full transaction consistently and check that that is ok.

This should offer some performance improvements I guess as Hibernate can then flush of it's accord. What are your views on this?

Thanks


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.