-->
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.  [ 2 posts ] 
Author Message
 Post subject: Transaction behavious on session.close()
PostPosted: Mon Dec 06, 2004 3:41 am 
Newbie

Joined: Mon Dec 06, 2004 3:32 am
Posts: 1
Hibernate version: 2.1

Hi All,

What is the behaviour of a transaction when the session that it was obtained from is closed via a call to Session.close() ?

Does this call cascade any other objects that were created by it as a call to Connection.close() does in JDBC with Statments etc?

If it does do a cascade clean up of objects created from it, what is the cleanup process for a transaction that has not been commited yet? Is a rollback called, a commit, or is the transaction just left hanging - tying up a connection and locking any database resources in use by it?

A common scenario might be when an exception is thrown mid transaction and close() is called from a finally section eg

Transaction tx = null;

try {
tx = session.beginTransaction();

// perform some code that causes an exception
} catch (HibernateException e) {
// handle exception
} finally {
session.close();
}


Cheers,

Ben


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 06, 2004 5:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Please note that your code forgets to call rollback on your transaction.

the session will call disconnect() and afterTransactionCompletion() which will release locks etc.

Hibernate does not do automatic rollback the properties of your instances in memory. (note: in HB3 there is id-rollback)

Note: the best doc for this is the code of session.close() and in Hibernate in Action

_________________
Max
Don't forget to rate


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