1 Reply Latest reply on Jun 4, 2008 1:49 AM by Jim Barrows

    Trying to map two fields to the same class

    Jim Barrows Newbie

      I have a class that keeps track of relationship data between two parties., so part of it looks like:

      Entity
      @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
      public class PartyRelationship extends BasePersistentModel{
      
       @Temporal(TemporalType.DATE)
       private Date fromDate;
      
       @Temporal(TemporalType.DATE)
       private Date thruDate;
      
       @Lob
       private String comment;
      
       @ManyToOne
       private PartyRole relationshipTo;
      
       @ManyToOne
       private PartyRole relationshipFrom;


      When I persist this, it goes to the database correctly. However when I retrieve the relationshipFrom field by itself, it doesn't get retrieved. I've looked at the code and can't see where it's mapping wrong.
      I force the bi-directional relationships here:
      @Override
       public String persist() {
       PartyRole relationshipFrom = getInstance().getRelationshipFrom();
       if( ! relationshipFrom.getInvolvedIn().contains( getInstance())){
       relationshipFrom.getInvolvedIn().add(getInstance());
       }
       PartyRole relationshipTo = getInstance().getRelationshipTo();
       if( ! relationshipTo.getInvolvedIn().contains( getInstance())){
       relationshipTo.getInvolvedIn().add(getInstance());
       }
       return super.persist();
       }

      And this works. Both the from and to are correct. When I pull the relationship class itself, all the fields are correct. It's only the PartyRole on the from side that doesn't get populated on retrieval, the to side works just fine.
      Any ideas on what I'm doing wrong?

        • 1. Re: Trying to map two fields to the same class
          Jim Barrows Newbie

          Okay, in essence:
          select r from Relationship r
          returns both partyRoles correctly.

          select pr from PartyRole pr where pr.id = :idOfToPartyRole
          returns pr.involvedIn, with the correct relationsihps

          select pr from PartyRole pr where pr.id= :idOfFromPartyRole
          does not return pr.invovledIn with any relationships.

          THis is all very confusing. It's the same code for both sides AND the DATABASE IS CORRECT.

          Any ideas why it's only the From Role Type that's doing this?