[jboss-user] [EJB 3.0] - Entity bean with compound PK containing FK

gavin.h@incubeta.com do-not-reply at jboss.com
Mon Sep 18 04:07:05 EDT 2006


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;
}



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3972208#3972208

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3972208



More information about the jboss-user mailing list