-->
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: How do you get SessionFactory's for multiple DataSources?
PostPosted: Sun Sep 14, 2003 10:08 pm 
Newbie

Joined: Sun Sep 14, 2003 8:29 pm
Posts: 6
Location: Tampa, FL
Hi,

How do you get instances of SessionFactory's that are associated to different datasources?

I see how you can give a SessionFactory a JNDI name. Then you could have multiple <session-factory> elements in your hibernate.cfg.xml, one for each datasource.

However, in this specific scenario I'm using TomCat which has a read-only InitialContext.

Is there another commonly used method for being able to get SessionFactory instances for different datasources?

By the way, I did read about one way using custom ResourceFactorys in TomCat. But this seemed overly complicated for what you would think is a very common scenario. I'm looking for any alternatives.

thanks,
matt


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 14, 2003 11:41 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You need multiple hibernate.cfg.xml files and load them accordingly, one .xml can only have one <session-factory>.

The "Usual Solution" at http://www.hibernate.org/114.html should be what you want, add some Factory Pattern magic on top or have a look at the Spring framwork. It is not neccessary to use a complicated design for this stuff, you just need some kind of Registry. You can also try the filesystem-based JNDI context from Sun.

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


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.