File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes How do you map two fields to the same class? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How do you map two fields to the same class?" Watch "How do you map two fields to the same class?" New topic
Author

How do you map two fields to the same class?

Jim Barrows
Greenhorn

Joined: Jun 05, 2008
Posts: 5
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

Joined: Aug 26, 2006
Posts: 4968
    
    1

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

Joined: Jun 05, 2008
Posts: 5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do you map two fields to the same class?