-->
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: Can hibernate connect to multiple databases ?
PostPosted: Wed Apr 28, 2004 1:39 am 
Beginner
Beginner

Joined: Sun Mar 28, 2004 7:18 pm
Posts: 26
I searched for "multiple databases" and "multiple datasources", but I dont think I came accross anything that gave me a definite answer.

I am developing a system whereby the same information can reside in multiple databases. For example, when a user wants to search for a policy, the policy# can reside in db1, 2 or 3. Depending on which database it's found in, I need to pull more info about that policy from that database.

I have used hibernate to connect to "a" database using the hibernate.properties in the past. Is it possible for hibernate to connect to different/multiple databases and if so, how does one do it ?

If someone could point me to a URL that solves this problem or someone can enumerate the steps that I need to take, I'd be really greatful.

I would be connecting to Oracle databases (9i).

Thanks in advance.
S


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 1:41 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can use two Configurations and two SessionFactories, but in your case, it makes much more sense to link the databases at the DBMS level. See your vendors documentation for that.

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


Top
 Profile  
 
 Post subject: To Christian
PostPosted: Wed Apr 28, 2004 1:50 am 
Beginner
Beginner

Joined: Sun Mar 28, 2004 7:18 pm
Posts: 26
Christian,

Can you please tell me briefly what you mean by connecting the databases as the DBMS level ? What does that mean and how would that solve my problem ? Is that akin to some global view that I would create ?

Pls let me know.
Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 1:58 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Exactly, see the Oracle documentation.

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


Top
 Profile  
 
 Post subject: Does hibernate map to Views ?
PostPosted: Wed Apr 28, 2004 9:16 am 
Beginner
Beginner

Joined: Sun Mar 28, 2004 7:18 pm
Posts: 26
Can I create mappings for tables AND views in hibernate ? Or just tables ?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 9:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
both


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 28, 2004 2:16 pm 
Newbie

Joined: Wed Apr 28, 2004 2:12 pm
Posts: 6
How about using SQL Server? For example, the current JDBC mechanisms look like:

SELECT a,b,c FROM <db>.dbo.<table>

where <db> is one of many possible databases, all structurally identical, but containing data for different parties. A set of credentials is available in the Http session from which I can obtain which <db> to connect to.

Thanks,
Tim Lucia
Nashua, NH


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 30, 2004 4:21 pm 
Newbie

Joined: Wed Apr 28, 2004 2:12 pm
Posts: 6
timlucia wrote:
How about using SQL Server? For example, the current JDBC mechanisms look like:

SELECT a,b,c FROM <db>.dbo.<table>

where <db> is one of many possible databases, all structurally identical, but containing data for different parties. A set of credentials is available in the Http session from which I can obtain which <db> to connect to.

Thanks,
Tim Lucia
Nashua, NH


Answer to my own question -- From the session, you get connection, and then call setCatalog on it, i.e.,

sessionFactory.openSession().connection().setCatalog("dbname");


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.