stefoid wrote:
Hi, Ive read this:
"Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html"
but I still dont u\quite understand it. When do I explicitly close a session?In my web app, the user logs on, then performs a bunch of operations which most likely involve database interaction over a half hour period, and doesnt really log off. they probably just close the browser or surf somewhere else.
Is it OK to open a session using hiberutil code, and never close it? or should I be explicitly calling close session after every group of database interactions?
cheers
You should close your session after groups of DB transactions, actually Hibernate 3.1 automaticly closes sessions when you call tx.commit();
However, there are some exceptions, for example BLOB fields are lazily initialized, that is to say you should keep your session opened until you call the getBLOBField method of your POJO object, otherwise an exception will be thrown.