Well, no problem for the question.
Actually, the classes are persisted when you call session.flush(). Most of the time, you do it inside a transaction context, which you can start via the session.beginTransaction() method.
Typically, as explained in the javadoc of the Session class, here is the classical way of doing things (
http://www.docjar.com/docs/api/org/hibe ... ssion.html):
Code:
Session sess = factory.openSession();
Transaction tx;
try {
tx = sess.beginTransaction();
//do some work
...
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
sess.close();
}
In the context of a web app, you've got multiple patterns for handling your session object, one of them is using a servlet filter. This pattern is called "open session in view" :
http://www.hibernate.org/43.html
--
Baptiste
PS : don't forget to give credits on the left if you found this answer useful :)