-->
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.  [ 3 posts ] 
Author Message
 Post subject: Querying multiple data sources.
PostPosted: Wed Jul 21, 2004 8:31 pm 
Newbie

Joined: Wed Jul 21, 2004 8:27 pm
Posts: 1
I started to develop persistance using Hibernate, a few weeks ago. Right now I'm facing a problem I can't figure out how to solve.

My app use data from two different datasources to populate a class. I will try to briefly exemplify my situation.


Code:
package database.one; //let's say this one is my production database.

/**
* @hibernate.class table="A"
*/

public class A {
private String id;
/**
  * @hibernate.id column="id"
  * generator-class="sequence"
  */
public String getId() { return id; }
public void setId(String id) { this.id = id; }
}

package database.two; //let's say this other is my development database.

/**
* @hibernate.class table="B"
*/

public class B{
private A a;
/**
  * @hibernate.many-to-one column="id"
  * class="database.one.A"
  * unique="true"
  */
public A getA() { return a; }
public void setA(A a) { this.a = a; }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 22, 2004 8:54 am 
Newbie

Joined: Wed May 12, 2004 5:12 pm
Posts: 8
Location: Frankfurt / Germany
I think you cannot do this in hibernate.

In addition to that I'd say that you should rethink this design. you should not use two different classes to access dev and prod databases.


Top
 Profile  
 
 Post subject: i think you can pass a connection to the session..
PostPosted: Thu Jul 22, 2004 2:22 pm 
Beginner
Beginner

Joined: Thu Jul 22, 2004 2:15 pm
Posts: 35
Hi..

I remember it from a while back, and I think this Session javadoc supports it too:
http://www.hibernate.org/hib_docs/api/n ... ssion.html

You can ask the session to reconnect to a certain JDBC connection. Now the session should use that JDBC connection for your deeds.

You might want to to use two session, one for prd one for dev..

SessionFactory can also take a JDBC connection
javadoc: http://www.hibernate.org/hib_docs/api/n ... ctory.html

when trying to open a new hibernate session.


HTH,
Paul


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