Do I need to place Hibernate.initialize() inside a transaction context? When I first asked myself, I thought it is a sure thing. The call needs to be place inside a transaction:
tx = session.beginTransaction();
session.lock(user, LockMode.NONE);
Hibernate.initialize(user.getSites());
tx.commit();
}catch (HibernateException e) {
if ( tx != null ) {
try {
tx.rollback();
} catch (HibernateException he) {
.......
}
}finally {
if (session!= null) {
try {
session.close();
} catch (HibernateException e) {
....
}
}
}
But everytime, I am getting a warning message as below,
WARN [net.sf.hibernate.impl.SessionImpl] - -
afterTransactionCompletion() was never called
If I remove the transaction and call Hibernate.initialize() directly. The WARN message never shows up. So I assume there is no need to initialize under a transaction context. Am I correct? If not, what do I need to do to make the warning message go away? I am a little bothered by that...
Thanks.
AW
|