Sorry for my poor english^^;
multithreaded evnvironment.
about 15 java application using hibernate session.
all java files have code like this.
Code:
session sess = null;
Transaction tx = null;
//some hibernate concern code 1
try{
sess = HibernateUtil.openSession();
tx = sess.beginTransaction();
....
}
catch(HibernateException e){
if( tx != null) tx.rollback();
session.close();
return;
}
// some plain java code 1 - business logic - long line
....
....
//some hibernate concern code 2
try{
sess.createQry..
....
sess.update..
}
catch(HibernateException e){
if( tx != null) tx.rollback();
session.close();
return;
}
// some plain java code 2 - business logic - long line
....
....
//some hibernate concern code 3
try{
sess.createQry..
....
sess.update..
sess.save..
}
catch(HibernateException e){
if( tx != null) tx.rollback();
session.close();
return;
}
// some plain java code 3 - business logic - long line
....
....
....
//some hibernate concern code n
try{
sess.createQry..
....
sess.update..
sess.save..
tx.commit();
}
catch(HibernateException e){
if( tx != null) tx.rollback();
}
finally{
session.close();
}
Is it right?
I think following is right usage.
Code:
session sess = null;
Transaction tx = null;
try{
sess = HibernateUtil.openSession();
tx = sess.beginTransaction();
//some plain java code 1
// it might be long and have other try catch clause
....
....
sess.update..
.....
//some plain java code 1
// it might be long and have other try catch clause
....
....
sess.save..
.....
//some plain java code 2
// it might be long and have other try catch clause
....
....
sess.delete..
.....
//some plain java code n
// it might be long and have other try catch clause
....
....
sess.update..
.....
catch(HibernateException e){
if( tx != null) tx.rollback();
}
finally{
session.close();
}
which one must I choose?
thanks in advance..