Javatpoint Logo

Session.openSession() & Session.getCurrentSession()?

By: venugo*** On: Tue Jun 11 13:25:32 EDT 2013     Question Reputation2 Answer Reputation0 Quiz Belt Series Points0  2Blank User
Hi Please Explain the
Difference between Session.openSession() & Session.getCurrentSession()?
Up0Down

 
Session.openSession():it creates a new session(for new session)
...

if u want to work with already existing session go for Session.getCurrentSession()
Image Created0Down

By: [email protected] On: Tue Jun 11 23:56:07 EDT 2013 Question Reputation0 Answer Reputation0 Belt Series Points0 0User Image
Are You Satisfied :5Yes3No
 
Thanks for Replay Krisinivasu

I accept but i can expect more explanation please provide more explanation

Advance Thanks
Image Created0Down

By: [email protected] On: Wed Jun 12 01:08:46 EDT 2013 Question Reputation2 Answer Reputation0 Belt Series Points0 2User Image
Are You Satisfied :2Yes2No
 
getSession gives you a Hibernate session, and associates that session with the current thread. Then, if you call getSession again, you get the session that was originally created. This is good.


getSession is usually sufficient. openSession provides and facilitates a greater level of management of where the session is stored and managed. It's certainly an advanced option, but one that does indeed fit the need of very clever developers who are doing some nifty things with the session.



* Using getCurrentSession () the created session bound to the current thread, and the use of openSession ()
Session is not created
* Use getCurrentSession () to create the session will automatically turn off when the commit or rollback, and using openSession ()
Create the session must be manually shut down



using the getCurrentSession () requires in hibernate.cfg.xml file add the following configuration:
* If you are using a local transaction (jdbc Affairs)
<property name="hibernate.current_session_context_class"> thread </ property>
* If you are using the global transaction (JTA transaction)
<property name="hibernate.current_session_context_class"> jta </ property>
Image Created0Down

By: [email protected] On: Wed Jun 12 06:02:10 EDT 2013 Question Reputation0 Answer Reputation392 Belt Series Points0 392User Image
Are You Satisfied :6Yes2No
 
Thank raviImage Created0Down

By: [email protected] On: Thu Jun 13 03:44:05 EDT 2013 Question Reputation2 Answer Reputation0 Belt Series Points0 2User Image
Are You Satisfied :0Yes0No