well i am not sure i am doing it well
but i made some class, named DataProvider
that in its ctor i did:
Code:
this.session = HibernateUtil.reserveSession();
this.transaction = this.session.beginTransaction();
and its is holding the session and the transaction all along.
then i implemented methods in it:
commit:
Code:
this.transaction.commit();
this.transaction = this.session.beginTransaction();
rollback:
Code:
this.transaction.rollback();
release:
Code:
HibernateUtil.releaseSession(this.session)
it got there some events and notification handling,
and some specific actions i need in my app, like save object, create new object, query stuff
so what i do in my app is create DataProvider and use it to save objects,
then i commit() or rollback() at the end.
sometimes i commit and keep working with the same DataProvider
untill i call the release() method.
the hibernateUtil:
Code:
reserveSession - sessionFactory.openSession()
releaseSession - session.close();
does this handling seems ok for you?