Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Mapping a Many-To-One Dependent Composition

 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting three times. My browser acted weird.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found the solution, which is explained here --> http://www.youtube.com/watch?v=010jX3jNhzw
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic