Hi,
A session closing problem. I'm using Hibernate 2.1.8.Here is the scenario.
class ABC{
public void saveOrder(Order o){
try {
Session hsession = HibernateUtil.currentSession();
Transaction tx = hsession.beginTransaction();
try {
hsession.saveOrUpdate(order);
//create default workcard.
ClassB b = new ClassB();
WorkCard wc = b.createWorkCard(order);
tx.commit();
hsession.flush();
hsession.close();
} catch (Exception e) {
tx.rollback();
hsession.close();
throw new ServiceTierException("error : "+e.getMessage(), e);
}
} catch (HibernateException e) {
try {
HibernateUtil.closeSession();
} catch (HibernateException he) {
throw new ServiceTierException("saveOrder(): closeSession() call failed", he);
}
throw new ServiceTierException("saveOrder()", e);
}
}
}
In the above code, ClassB also calls for HibernateUtil.getCurrentSession() and do a txn(saving WorkCard) with database and commit and close the session. When ClassB does that and return, Class ABC cannot commit the txn(marked red) but throws an exception saying "SessionClosed".
So, how to handle when there are txns across different classes and when we don't know when to close the session ?
Any help would be highly appreciated.
Thanks
Viji
|