How properly "lifecycle" of a Hibernate session under Spring should be done?
The SessionFactory
is created automatically by Spring and is taking its DB connections from Glassfish connection pool. At the moment I am getting a Hibernate session via SessionFactory.getCurrentSession()
. Then I start transaction, do the work and then commit()
or rollback()
at the end. Do I need to do any other actions like disconnect()
, close()
, flush()
or any others at any time so connections would be properly returned back to the pool or is everything already automatically done by Spring?
With plenty of these methods it is a little confusing for me at the moment to understand when what should be done, maybe someone can point to right direction?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…