wood burning stoves 2.0*
The moose likes Object Relational Mapping and the fly likes Mapping a Many-To-One Dependent Composition Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mapping a Many-To-One Dependent Composition" Watch "Mapping a Many-To-One Dependent Composition" New topic
Author

Mapping a Many-To-One Dependent Composition

Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Hi ...

I am facing some issues when mapping a dependent composition in hibernate and would appreciate some advice .

Here is the case:

A person can have several favorite cities. So, the relational model looks like this.



What I want now is a domain model where I can obtain a set of Favorite Cities from the Person object, like this.



Now for the FavoriteCity object, I don't want the Person to be referenced in it (to prevent the cycle and also because FavoriteCity is dependent on Person - no person no city).
Also, when adding a city, i don't want to associate the city with the person to then add the city to the person. From a domain driven perspective, this doesn't make much sense, as the relation to the person in implicated by the person to whom the city is added.

So, what I don't want is:



Instead I want:



The problem now is that I am not sure how this would be mapped in the hibernate mapping.

Hope anyone can assist


JDBCSupport - An easy to use, light-weight JDBC framework -
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Sorry for posting three times. My browser acted weird.
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
I found the solution, which is explained here --> http://www.youtube.com/watch?v=010jX3jNhzw
 
jQuery in Action, 2nd edition
 
subject: Mapping a Many-To-One Dependent Composition
 
Similar Threads
Hibernate Persisting model
[Hibernate] many-to-many, invalid primary key in the join table?
ORA-02291: integrity constraint, can not find parent key
How to insert a new child record only. One to Many Relation.
embedded class question