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

How do you map two fields to the same class?

 
Jim Barrows
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class called Relationship, and a class called Party.
A party can have 1+ relationships, and a relationship is between two parties.
So mapping looks like:

Party kind of looks like:


I can persist the Relationship, and both parties make it into the database, and the database is populated correctly.
However, when I retrieve the toParty it does NOT know about the relationship it's involved in. The fromParty however does know about the Relationship, and the Relationship knows about both parties.

Anybody have any ideas on how to get the toParty to have the relationship list populated correctly?
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to need to make the relationship bidirectional. I have a free tutorial on creating one to many and many-to-one mappings that use a Player and a Team - similar to your scenario. Here are the annotations on each side:





 
Jim Barrows
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is a bi-directional mapping. That's not the question.
The question is that I have TWO fields pointing to the SAME class, and ONE of the fields is not getting populated on the other side correctly. The from field is not getting it's list of relationships populated at all. The to field however is getting populated correctly. The database is populated correctly.
And, as an added note it is whatever field I declare second, the first field always gets populated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic