Quote:
If you have classes A, B and C, all three not related comment parent or by inheritance. You also have a fourth class called X, again not related to the previous three. Your object model has the following one-to-many relationships
A---on-to-many--->X
B---on-to-many--->X
C---on-to-many--->X
The question is: How best to implement all three relationships between A and X, B and X, C and X using Hibernate? There are some well-known solutions in standard object-modeling theory, like using a joint-table, but I would like to get an answer from the makers of Hibernate to see if they created something to handle this particular case. As far as I know, this topic is not mentioned in the “Java Persistence with Hibernate” book.
I am not so sure that Hibernate would need anything special to handle this case. Its a matter of Database design & theory. If there is no commonality between A, B, and C (ie: they each represent their own table) Then the only way to reference X by any of them is through a Join-Table or via ForeignKey relationship. In these cases, Hibernate already fully supports either mechanism, going both directions along the relationship.
IMHO: You shouldn't model your relationships of your data model based on what Hibernate (or any tool for that matter) supports. Instead model it based on the true relationship, and then figure out how to support that realization using whatever tool you've decided on (Hibernate in this case).
-B