-->
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.  [ 6 posts ] 
Author Message
 Post subject: Session HibernateUtil class
PostPosted: Mon Feb 16, 2004 10:33 am 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Hi all,

I was trying to use hibernate with the examples and I wonder what about avantage to use the class HibernateUtil?

Is this to have a to make the Configuration().configure().buildSessionFactory() only once at the beginning of the application? And I have read the doc but I'm not sure to understand the use of the ThreadLocal attribute, is this to be able in a multi thread or distributed context to be able to retrieve an open session. But in this case a static attribute in a static class is sufficient?

Any help on this is very welcome.

Thanks.

Vlad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 10:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
The ThreadLocalSession pattern is used to have exactly one session per thread and not having to pass it around through method calls. Read the Java API for ThreadLocal.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 10:36 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Yes, read more about the ThreadLocal Session pattern here, also check the IBM article:

http://www.hibernate.org/Documentation/ ... calSession
http://www.hibernate.org/Documentation/ ... ctionScope

http://www-106.ibm.com/developerworks/j ... eads3.html

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 10:38 am 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Is this a problem if I have two sessions at the same time?

And is this better to close a session as soon as work is done or can we let it open for futher use, this is probably time consuming?

Vlad


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 10:47 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please read the stuff christian posted, it is quite well outlined there what your options are.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 16, 2004 10:48 am 
Regular
Regular

Joined: Thu Feb 05, 2004 6:51 am
Posts: 50
Yes I sax it just after posting, thanks for so quick response.

Vlad


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.