aspose file tools*
The moose likes Object Relational Mapping and the fly likes Single Entity to multiple tables mapping Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Single Entity to multiple tables mapping" Watch "Single Entity to multiple tables mapping" New topic
Author

Single Entity to multiple tables mapping

Dean Decasse
Greenhorn

Joined: Nov 29, 2012
Posts: 2
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

Joined: Mar 07, 2010
Posts: 1680
    
    7

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


[How To Ask Questions][Read before you PM me]
Dean Decasse
Greenhorn

Joined: Nov 29, 2012
Posts: 2
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

Joined: Mar 07, 2010
Posts: 1680
    
    7

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

Joined: Dec 01, 2012
Posts: 7

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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Single Entity to multiple tables mapping