-->
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.  [ 8 posts ] 
Author Message
 Post subject: Storing SessionFactory in JNDI or class variable
PostPosted: Thu Feb 19, 2004 5:18 am 
Newbie

Joined: Thu Feb 19, 2004 5:11 am
Posts: 3
Hello

I'm currently investigating using Hibernate inside a WebLogic EJB container and was wondering if there were any advantages of storing a SessionFactory object in JNDI as opposed to using the ThreadLocal pattern and storing the SessionFactory in a static variable.
Also, since the EJB container will be clustered, we'll have more than one SessionFactory accessing the same database. Could this potentially pose any problems?

Many thanks in davance

Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 5:44 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Don't put SessionFactory in a thread local variable. It is useful for session storage.
This SF should be unique : use either JNDI or singleton.

Have 1 SF per cluster nodes is just fine.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 5:55 am 
Newbie

Joined: Thu Feb 19, 2004 5:11 am
Posts: 3
Yes, sorry that's what I meant. Storing the SessionFactory as a Singleton in a class variable and storing sessions in ThreadLocal.
So there are no advantages of putting the SessionFactory in JNDI over using a Singleton? In that case I better use a Singleton since I don't manage to bind it to the JNDI context in WebLogic.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2004 7:06 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It has an advantage: classloader headache
If you want to use your SF in your webapp and un your ejbs, then the classloader may be different and the singleton too.
But I personnally keep it in a singleton.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 17, 2004 11:40 pm 
Beginner
Beginner

Joined: Thu Jun 17, 2004 11:25 pm
Posts: 21
Location: Los Angeles
Emmanuel,

Are you sure it is OK to have one SessionFactory shared across several machines in a cluster? I can't find any documentation stating that and I'd be worried that caches, JDBC connections, etc. would be improperly handled when the SessionFactory was serialized and shipped over to another machine in response to a JNDI lookup.

=Jeremy=


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 21, 2004 3:25 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
jgro wrote:
Are you sure it is OK to have one SessionFactory shared across several machines in a cluster?

It does not work for sure, I haven't said that (I guess ;-) )
Use one SF per JVM.

_________________
Emmanuel


Top
 Profile  
 
 Post subject: How many SessionFactory objects in a cluster?
PostPosted: Mon Jun 21, 2004 3:42 pm 
Beginner
Beginner

Joined: Thu Jun 17, 2004 11:25 pm
Posts: 21
Location: Los Angeles
OK, I'll use one SessionFactoy per JVM.

Just to clarify, you said:
Quote:
This SF should be unique : use either JNDI or singleton.

When you use JNDI in a cluster, by default most appservers will replicate a non-managed object such as a SessionFactory across the cluster.

You said:
Quote:
Have 1 SF per cluster nodes is just fine.

Normally I wouldn't correct anyone's grammar but in this case what you said is unclear to the point that it could mean either of the two possible choices so I had to ask did you mean a) Having 1 SF for each cluster node is just fine or b) Having 1 SF for the entire cluster is just fine. I understand now that you meant (a). Right?

=Jeremy=


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 12:21 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1 session factory per JVM.

_________________
Emmanuel


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