Hibernate version: 3.2.5
Name and version of the database you are using:Oracle
I am developing a tomcat servlet database admin tool using hibernate. It must allow the user to be able edit, insert, delete records over a period of servlet requests. I.e. search for a record, edit it, search for something else etc etc... It must also allow the user to be able to commit/rollback when he or she chooses.
The most relevent documentation I have found is
"the extended Session pattern for long Conversations" found here:
http://www.hibernate.org/43.html#A5
However this appears to commit the transaction after every request which is not what I am looking to do.
The setup I have at the moment is as follows:
Store a reference to the Hibernate Session in the HTTP Session.
Before processing a servlet request reload the session and bind:
Code:
if (session == null) {
session = sf.openSession();
session.setFlushMode(FlushMode.MANUAL);
ManagedSessionContext.bind(session);
session.beginTransaction();
} else {
ManagedSessionContext.bind(session);
}
If the user chooses to commit:
Code:
session = ManagedSessionContext.unbind(sf);
session.flush();
session.getTransaction().commit();
session = null;
If the user chooses to rollback:
Code:
session = ManagedSessionContext.unbind(sf);
session.flush();
session.getTransaction().rollback();
session = null;
This setup appears to be working as expected but it was more a result of
hacking it together than really knowing what I was doing! Can anyone see any flaws in the setup?
Cheers in advance