this common problem in hibernate transaction can be solved by defining a new session ojbect for each transaction and commit or rollback the transaction in the DataAccess Object level.
Following code snippet in DAO level was used to solve the problem:
Transaction tx=null;
Session sess = SessionFactoryUtils.getNewSession(getSessionFactory());
try {
tx = sess.beginTransaction();
sess.saveOrUpdate(updatedModel);
tx.commit();
}
catch (JDBCException e) {
return false;
}
catch(Exception ex){
System.out.println("****************************exception sent"+ex.getMessage());
}
finally {
sess.close();
}
Thanks,
Ramesh.
Following code snippet in DAO level was used to solve the problem:
Transaction tx=null;
Session sess = SessionFactoryUtils.getNewSession(getSessionFactory());
try {
tx = sess.beginTransaction();
sess.saveOrUpdate(updatedModel);
tx.commit();
}
catch (JDBCException e) {
return false;
}
catch(Exception ex){
System.out.println("****************************exception sent"+ex.getMessage());
}
finally {
sess.close();
}
Thanks,
Ramesh.
Great..
ReplyDelete