0 Replies Latest reply on Sep 18, 2006 4:07 AM by gavin.h

    Entity bean with compound PK containing FK

    gavin.h

      It looks like the EJB3 spec does not support an entity bean with a FK as part of its compound PK. I've managed to find JBoss/hibernate docs which describe their work around for the problem, and I've managed to get that to work.
      The last hurdle that I can't figure out is how to map the reverse association. It looks like the ManyToOne in the Embedded PK isn't actually part of the EntityBean and so I can't reference it in the mapped by clause from the associated Entity Bean.


      Abbreviated table structure is as follows:

      tblParent
      parentId (PK)
      ...

      tblChild
      parentId (FK) (PK)
      sequence (PK)
      ...


      Very Abbreviated Entities as follows:

      @Entity
      public class ParentBean {
      ...
      /** HOW SHOULD I ANNOTATE THIS **/
      @OneToMany(mappedBy="parent") <-- DOESNT WORK
      @OneToMany(mappedBy="pk.parent") <-- DOESNT WORK
      public Set< ChildBean > getChildren();
      public void setChildren(Set< ChildBean > children);
      ...
      }


      @Entity
      @AssociationOverride( name="pk.parent", joinColumns = @JoinColumn(name="parent_parentId") )
      public class ChildBean {
      @EmbeddedId public ChildPK pk;

      }


      @Embeddable
      public class ChildPK {
      @ManyToOne
      public ParentBean parent;
      public Integer sequence;
      }