-->
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: Member variable referencing separate table or database?
PostPosted: Tue Jul 06, 2010 11:22 am 
Newbie

Joined: Thu Jul 01, 2010 12:45 pm
Posts: 11
I have a Hibernate object where I need a member variable to reference an object that points to a different database. So for example, I need something like this:

Code:
@Entity
@Table(name = "hibernate_test")
public class HibernateObject implements Serializable {
   private static final long serialVersionUID = -8889984662603797899L;
   
   public HibernateObject() {

   }

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "id")
   Integer id;

   @Column(name = "name")
   String name;

   EnrichedColumn object; // This object would point to a different database
   
   public void setEnrichedColumn(EnrichedColumn col) {
      this.object = col;
   }
   
   public EnrichedColumn getEnrichedColumn() {
      return this.object;
   }
   
   public Integer getId() {
      return id;
   }

   public void setId(Integer id) {
      this.id = id;
   }
   
   public void setName(String name) {
      this.name = name;
   }
...
}


And the EnrichedColumn object member variable would point to an object that looked like this:

Code:
@Entity
@Table(name = "enriched_column_test")
public class EnrichedColumn {
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "id")
   Integer id;
   
   @Column(name = "name")
   String name;

   public EnrichedColumn() {
      
   }

   public Integer getId() {
      return id;
   }

   public void setId(Integer id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }
}


Is there any way to do this?


Top
 Profile  
 
 Post subject: Re: Member variable referencing separate table or database?
PostPosted: Wed Jul 07, 2010 9:20 am 
Newbie

Joined: Wed Sep 24, 2008 12:48 pm
Posts: 6
if you use oracle there's a way to "map" tables between schemas with aliases (or even different databases with oracle RAC). If you are using any free db (mysql, postgress,etc) you won't be able to do it.

The "idea" is that the DB has to allow you to map a table to your schema.


If you can't do that, then you'll need to create 2 hibernate sessions (one for each db) and forget about having any type of funky mapping, you'll need to map ids and then recover the entity with the other hibernate session.


Top
 Profile  
 
 Post subject: Re: Member variable referencing separate table or database?
PostPosted: Wed Jul 07, 2010 9:48 am 
Newbie

Joined: Thu Jul 01, 2010 12:45 pm
Posts: 11
augusto.rodriguez wrote:
if you use oracle there's a way to "map" tables between schemas with aliases (or even different databases with oracle RAC). If you are using any free db (mysql, postgress,etc) you won't be able to do it.

The "idea" is that the DB has to allow you to map a table to your schema.


If you can't do that, then you'll need to create 2 hibernate sessions (one for each db) and forget about having any type of funky mapping, you'll need to map ids and then recover the entity with the other hibernate session.


That's kind of what I was afraid of... I can use 2 hibernate sessions and just pass along the unique ID, but I wanted to be able to use Hibernate Search to automatically index the whole shebang without having to deal with multiple sessions and what not.


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.