-->
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.  [ 4 posts ] 
Author Message
 Post subject: Singleton Session Factory - Clarification
PostPosted: Sat Apr 10, 2010 12:50 pm 
Newbie

Joined: Sat May 09, 2009 3:19 pm
Posts: 9
Just to be clear. There is no reason why a session factory HAS to be a singleton. The only reason is to save on the resources needed to create and destroy one.
Am I correct in assuming that a Hibernate program would work just as correctly using a non-singleton session factory, just less efficiently?


Top
 Profile  
 
 Post subject: Re: Singleton Session Factory - Clarification
PostPosted: Tue Apr 20, 2010 11:00 am 
Newbie

Joined: Sat May 09, 2009 3:19 pm
Posts: 9
Is this really that difficult a question to answer?


Top
 Profile  
 
 Post subject: Re: Singleton Session Factory - Clarification
PostPosted: Tue Apr 20, 2010 5:10 pm 
Newbie

Joined: Tue Apr 20, 2010 3:40 pm
Posts: 3
I'm a newb, so i don't know, but I think there may be an issue with concurrent transactions and atomicity and such if you have multiple sessions, unless you do something special to avoid it. However, I'm just using a Spring sessionfactory bean and passing it into everything that needs it.


Top
 Profile  
 
 Post subject: Re: Singleton Session Factory - Clarification
PostPosted: Tue Apr 20, 2010 5:17 pm 
Newbie

Joined: Tue Apr 20, 2010 3:40 pm
Posts: 3
Actually, I think I'm incorrect. The sessions created by the factory are the ones that aren't threadsafe.

http://63-246-22-42.contegix.com/hibern ... tions.html

But i'd say it's pointless to have more than one sessionFactory. Please let me know if I'm wrong :-). But I wouldn't bother explicitly making it a singleton either. Singletons are bad, equivalent to globals. Dependency Injection is a better alternative.


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