jamesh wrote:
pksiv wrote:
jamesh wrote:
I have a fat client and I'm using one session for the whole application. I disconnect the session when I'm done with it. However, any time there is an exception or if I wanna do something with a new thread. It creates another sessions by itself and then I get the error that says the object is associated under more then one session.
How can I avoid these? Thanks...
Read section 12.1.4 in the latest docs. It specifically says that you need to close your session if you get an exception.
As for the new session per thread, if you're using the ThreadLocal pattern for sessions described in Hibernate In Action, it will open a new session for each Thread.
Yes I'm using ThreadLocal pattern. and I read that part too. I guess now my question is should I still use one session for the whole application or should I switch to session per request?
Thanks
I've read many posts about this on here and while I think it might be okay to use 1 session for the whole application, everything I've read is that a Session is very lightweight and meant to be created many times so I don't think you'd have a problem with this approach.
You can read section 12.3.2 for more information on Long running sessions. Specifially, it talks about disconnecting from the JDBC connection when your waiting on the user so you don't tie up the connections during user think time.
I work with mostly webapps so the One Session-per-request works best for me. But I actually think this approach simplifies things in all cases.