-->
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: if i don't roll-back a transaction will i lose the Session
PostPosted: Thu Oct 26, 2006 1:15 am 
Beginner
Beginner

Joined: Tue Sep 19, 2006 5:46 am
Posts: 21
Location: india
hi,

I am using a begin transaction and commit transaction if the commit fails

i am not calling the rollback() method. if the commit fails will the entire Session for the entire application will be closed. or the session will be there for using it in other methods in the application.

This is my code example,

public void saveBankValue(
BankValue persistentInstance) {
log.debug("save BankValue instance");
try {
sessionFactory.getCurrentSession().beginTransaction();
sessionFactory.getCurrentSession().save(persistentInstance);
sessionFactory.getCurrentSession().getTransaction().commit();
log.debug("save successful");
} catch (RuntimeException re) {
log.error("save failed", re);
throw re;
}
}
-------------------------------------------------
see there is no rollback() in catch block. will this close the session when commit fails and effect other methods in the class which uses the same session factory

please give me an answer on this.

Thanks,
Joseph.C

_________________
JosephC


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 6:20 am 
Senior
Senior

Joined: Mon Oct 23, 2006 5:12 am
Posts: 141
Location: Galicia, Spain
Form hibernate doc (9.8 exception _Handling):
---------------------------------------------------------------------------------------------------
If the Session throws an exception you should immediately rollback the
transaction, call Session.close() and discard the Session instance.

(...)

Session sess = factory.openSession();
Transaction tx = null;
try {
tx = sess.beginTransaction();
// do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
---------------------------------------------------------------------------------------------------
With the typical transaction configuration of Hibernate applications
executing "tx.rollback" will close automatically the session.

Hope this helps...

_________________
andresgr (--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.