-->
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 to connect to more than one database
PostPosted: Mon Apr 17, 2006 10:14 am 
Beginner
Beginner

Joined: Mon Feb 27, 2006 11:16 am
Posts: 25
To Whom It May Concern:

I am currently using Hibernate 3.05, MyElicpse 4.1.1, Tomcat 5.5, JTDS driver for Microsoft SQL 2000, Microsoft SQL 2000.

Does anybody know how to use Hibernate to connect to more than one database. Can anybody send me a link or url that talks about how to do this in Hibernate.
How do we make it so that one domain object is connect to one datasource and another domain object is connect to another data source.


Yours,

Desperate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 10:36 am 
Expert
Expert

Joined: Thu Sep 22, 2005 10:29 am
Posts: 285
Location: Almassera/Valencia/Spain/EU/Earth/Solar system/Milky Way/Local Group/Virgo Supercluster
Code:
Configuration cfg1 = new Configuration()
    .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
    .setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test1")
    .setProperty("hibernate.order_updates", "true")
    .addResource("map1_1.hbm.xml")
    .addResource("map1_2.hbm.xml");
SessionFactory sessions1 = cfg1.buildSessionFactory();
Session session1 = sessions1.openSession();

Configuration cfg2 = new Configuration()
    .setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLInnoDBDialect")
    .setProperty("hibernate.connection.datasource", "java:comp/env/jdbc/test2")
    .setProperty("hibernate.order_updates", "true")
    .addResource("map2_1.hbm.xml")
    .addResource("map2_2.hbm.xml");
SessionFactory sessions2 = cfg2.buildSessionFactory();
Session session2 = sessions2.openSession();


But you cannot mix the mapping files. Every POJO and their properties will be connected with one database. You cannot have one property mapped to one database and another property mapped to other database.


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.