Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Single Entity to multiple tables mapping

 
Dean Decasse
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

I am new to Hibernate (and O/R mapping in general), and was wondering if someone could help me figure out the following:

Assume I have tables T1, T2, T3, T4, T5 and T6 related as:

T1 ----- T2 ----- T4 ----- T6
|             |
|             |
T3         T5

Now, assume that I have only one entity and that its fields are mapped to columns in T3, T5 and T6. I dont have any other entities. Is it possible to make this mapping (in HIbernate/JPA)? (I think it is not, but would very much appreciate someone's oppinion on it).

Thank you,
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The example is kind of abstract is this what you are looking for? Perhaps provide a simple example of the tables and what you want your Entity to look like

http://uaihebert.com/?p=46
 
Dean Decasse
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Bill for your reply.

The question I wanted to ask above (and I guess I did not ask it right) was if, for example, the primary table to which my entity if mapped is T2, then I could use @SecondaryTable annotation to map some of its fields to tables T1 and T4, but I cannot map any of its fields to tables T3 and T6. In other words, I can map a single entity to multiple tables that are in "star"-like schema (they have to be immediate neighbours of the primary table to which the entity is mapped).

Here is the example again:

T1 ----- T2 ----- T4 ----- T6
|             |
|             |
T3         T5





Would that be correct?

Thank you very much
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If your question is can I have one single entity that is mapped to 6 different tables where the primary table does not have a relationship with some of the tables the answer is no. In this case you would have to create another entity to be used in the composition to define those relationships on.
 
Ben Morse
Greenhorn
Posts: 7
Chrome MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you maybe describe the underlying data you are trying to store, and why you are trying to do an interesting mapping like this? That might help us give you better answers.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic