Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate Difference between getCurrentSession() and openSession() in Hibernate ?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Rahul Dev
Difference between getCurrentSession() and openSession() in Hibernate ?
1 Answer(s)      3 years and 11 months ago
Posted in : Hibernate


What is difference between getCurrentSession() and openSession() in Hibernate ?


Advertisement
View Answers

October 26, 2010 at 3:58 PM


getCurrentSession() :

The "current session" refers to a Hibernate Session bound by Hibernate behind the scenes, to the transaction scope. A Session is opened when getCurrentSession() is called for the first time and closed when the transaction ends. It is also flushed automatically before the transaction commits. You can call getCurrentSession() as often and anywhere you want as long as the transaction runs. To enable this strategy in your Hibernate configuration:

set hibernate.transaction.managerlookupclass to a lookup strategy for your JEE container set hibernate.transaction.factory_class to org.hibernate.transaction.JTATransactionFactory

Only the Session that you obtained with sf.getCurrentSession() is flushed and closed automatically.

openSession() :

If you decide to use manage the Session yourself the go for sf.openSession() , you have to flush() and close() it. It does not flush and close() automatically.



Related Tutorials/Questions & Answers:
 

 

 

DMCA.com