-->
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: SessionFactory.getCurrentSession();
PostPosted: Fri Feb 24, 2006 10:09 am 
Beginner
Beginner

Joined: Wed Aug 04, 2004 4:33 am
Posts: 45
Location: Switzerland
Hibernate version:
3.1.2


I'm migrating to hibernate 3 from hiberante 2. I still have a HibernateHelper class which manages the current sessions and transactions. This was needed in hibernate 2. Hibernate 3 can handle it's own current session. So what do I do?

This:

public Session getSession() {
Session session = sessionFactory.getCurrentSession();
try {
if (session == null) {
Interceptor interceptor = threadInterceptor.get();
if (interceptor == null) {
session = sessionFactory.openSession();
}
else {
session = sessionFactory.openSession(interceptor);
}
}
}
catch (HibernateException he) {
throw new FrameworkRuntimeException("Couldn't open a new session.", he);
}
return session;
}


So I check if there is a current session, if no I create one, if there is an interceptor, i open the session with it.
Problem the getCurrentSession method opens a new one if none exists? Does this make sense, how should I solve it, keep the old HibernateHelper which keeps its own current session?


Top
 Profile  
 
 Post subject: numerous options
PostPosted: Tue Feb 28, 2006 6:19 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
- You can keep your approach;
- do it more elegantly with CGLib based proxies
http://sandbox.sourcelabs.com/kosta/hb- ... /haop.html
- use Spring (although not the the HibernateTemplate) or HiveMind (HiveTranse);

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.