Hibernate session management for multiple transactions ?
What is the best way for maintaning Hibernate session for multiple database transa开发者_C百科ctions? Do I need to open and close each session every time or should I rely upon getCurrentSession()
? Whats the best approach?
I think, the best approach will be to obtain sessions via openSession()
and release them via disconnect()
. This will cause the database connection to be returned to the Hibernate connection pool, and thus, if you're not executing all trasactions at once, your sessions will be created from the existing connections (where possible) and overall performance will be sane.
精彩评论