0 Replies Latest reply on Sep 18, 2006 4:07 AM by Gavin Hardie

    Entity bean with compound PK containing FK

    Gavin Hardie Newbie

      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:

      parentId (PK)

      parentId (FK) (PK)
      sequence (PK)

      Very Abbreviated Entities as follows:

      public class ParentBean {
      @OneToMany(mappedBy="parent") <-- DOESNT WORK
      @OneToMany(mappedBy="pk.parent") <-- DOESNT WORK
      public Set< ChildBean > getChildren();
      public void setChildren(Set< ChildBean > children);

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


      public class ChildPK {
      public ParentBean parent;
      public Integer sequence;