-->
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.  [ 5 posts ] 
Author Message
 Post subject: Different databases, same entities
PostPosted: Thu Sep 21, 2006 1:52 pm 
Newbie

Joined: Wed Oct 26, 2005 3:37 am
Posts: 15
Hello!

Here is the situation I have:
There are multiple legacy SQL Server databases with exactly the same structure. Each database holds data for a specific customer and this is how it's gonna be due to business requirements.
So, what I wanna do is, when user tries to log in, he/she should provide also the database name along with his/her credentials. Then I could pick up the proper SessionFactory for the database and use it to manage persistence.
Is it possible to do that via configuration or programatically (like adding mapped classes for each Factory configuration)?
Have anyone had a similar situation and what could be a good decision?
Btw, I would like to use Hibernate 3.x for that project.

Any ideas would be appreciated. Thank you.

Jana Parvanova


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 2:34 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
I believe it is possible.

Well you can have different session factories for different databases, and all your entities must be mapped in each session factory.

after login, use the proper session factory for each user to create proper session and the rest of the work is the same.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 2:36 am 
Senior
Senior

Joined: Sat Nov 27, 2004 4:13 am
Posts: 137
I believe it is possible.

Well you can have different session factories for different databases, and all your entities must be mapped in each session factory.

after login, choose the proper session factory for each user to create session and the rest of the work is the same.
--------------------
don't forget credits.

_________________
don't forget to credit!

Amir Pashazadeh
Payeshgaran MT
پايشگران مديريت طرح
http://www.payeshgaran.co
http://www.payeshgaran.org
http://www.payeshgaran.net


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 9:20 am 
Beginner
Beginner

Joined: Wed Jun 21, 2006 10:08 am
Posts: 26
It is possible. For each database you would need a seperate Hibernate Configuration, pointing at a different DB. Each configuration would be it's own SessionFactory.

How you actually set it up can get complicated. Off the top of my head, I would just hardcode each configuration for each client, and depending on who logs in use the appropriate SessionFactory that is already in the JVM.

If there are too many clients you would probably have to devise some sort of SessionFactory pool, that creates a NEW SessionFactory if he is the only user hitting DB1. If another user logs on and needs DB1, the SessionFactory would already be there and he would take part in it. When no other users needs DB1, the SessionFactory would be destroyed (to save memory).

The main point to remember is that it's a 1-1-1 relationship of Configurations-SessionFactory-Database.

_________________
- Jonathan


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 22, 2006 9:51 am 
Newbie

Joined: Wed Oct 26, 2005 3:37 am
Posts: 15
Thank you for the replies.
It was kinda what I imagined (building Session Factories when needed and adding mapped classes to them). I guess I should just give it a try.


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