-->
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: Mapping to different databases per request
PostPosted: Tue Jul 26, 2005 1:29 pm 
Newbie

Joined: Tue Jul 26, 2005 1:25 pm
Posts: 14
Here's the situation: Multiple users will be connecting to my application, and each user is hitting a different database for their storage.

So, after I log my user in and I see who I'm working with, is there a way to modify my Hibernate connection so that it hits a particular database?

Thanks in advance,
S


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 1:46 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
This sort-of related answer in the FAQ might point you in the direction you need.

http://www.hibernate.org/117.html#A12


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 4:27 pm 
Newbie

Joined: Tue Jul 26, 2005 1:25 pm
Posts: 14
Thanks for your answer.

I followed the link to this help topic: Hibernate is leaking JDBC connections!

I'm not having connection troubles - that's all working quite well for now as I'm directing everything through one database. Basically, my problem is that I'm using one hibernateUtil for all session management, and it's set up for a particular database:

DocumentBuilderFactory fct = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = fct.newDocumentBuilder();
Document doc = docBuilder.parse("example.cfg.xml");
Configuration cfg = new Configuration();
cfg.configure(doc);
sessionFactory = cfg.buildSessionFactory();

It sets all this up on initialization in the static constructor for hibernateUtil. Is there a way to initialize my hibernateUtil, and then later call a method to specifiy which cfg.xml to use?

Thanks in advance,
S


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 4:30 pm 
Regular
Regular

Joined: Thu May 26, 2005 2:08 pm
Posts: 99
Do you want a different connection per user or a different hibernate.cfg.xml per user? You've indicated both now. I assumed that you meant connection, based on your first post. Did you read the end of that FAQ entry I linked where they talk about how to change the connection after Hibernate is already initialized?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 4:30 pm 
Beginner
Beginner

Joined: Thu Jul 07, 2005 7:12 pm
Posts: 25
From that same FAQ:

- How do I use multiple databases?

- You must configure multiple SessionFactory instances.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 26, 2005 4:40 pm 
Newbie

Joined: Tue Jul 26, 2005 1:25 pm
Posts: 14
I'd like to reference a different cfg.xml for each client. I did see the section:

Quote:
How do I use multiple databases?
You must configure multiple SessionFactory instances.


Although, i was hoping there was a bit more hope out there than that. We have HibernateUtil calls sprinkled throughout the app, and if I needed to create a completely separate sessionFactory it was going to cause some serious reconstruction or duplicate code.

Thank you very much for your input -
S


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.