-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: session = sessionFactory.getCurrentSession(); problem
PostPosted: Fri Jun 06, 2008 4:05 pm 
Newbie

Joined: Thu May 22, 2008 2:16 pm
Posts: 9
What is the difference between

Code:
Session openedSession = HibernateManager.openNewSession();


and
Code:
sessionFactory.getCurrentSession();
method.

Is the latter one, would open a session, if there isn't an opened session.
I know that latter one also need a configuration line in hibernate.cfg.xml file. ( <property name="current_session_context_class">thread</property>) And if I didn't write this line hibernate give me an error. Do I really need this line in my hibernate.cfg.xml file and How can I handle session management in my HibernateManager code ?

I am not really sure for this issue and need experts advices.

Thank you

anut


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 07, 2008 7:37 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Here's actually an interesting discussion on that very topic at JavaRanch:

http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=78&t=003806

The getCurrentSession() method looks at the current context to see if a session is stored in there. If there is one, it uses it, and if there isn't a session in the current context, it creates a new one and saves it in there.

On the other hand, openSession does not try to store the session, or pull the session from the current context. I think the expectation is that you, as the developer, are going to store the session in a special scope of your own.

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.