Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Primary key foreign key entity relationship issue

I just follow the way you mentioned, but there is still an error ========================================== @Entity class A { @Id @Column(name="A_ID") @GeneratedValue(strategy = GenerationType.AUTO) private String aId; } @Entity @IDClass(BID.class) class B { @Column(name="B_ID") @Id private int bId; @Id @ManyToOne(cascade = ALL) @JoinColumn(name="A_ID", referencedColumnName="A_ID") @XmlTransient private A abc; } class BID{ int bId; //same type and name as the id from B String abc;//must be the same type as A's id, and the attribute must use the name of the relationship from B } =============================================== Exception [EclipseLink-7150] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.ValidationException Exception Description: Invalid composite primary key specification. The names of the primary key fields or properties in the primary key class [ca.gc.rcmp.rtid.entities.SubjectFilePK] and those of the entity bean class [class ca.gc.rcmp.rtid.entities.SubjectFile] must correspond and their types must be the same. Also, ensure that you have specified ID elements for the corresponding attributes in XML and/or an @Id on the corresponding fields or properties of the entity class.
luke2010 wrote:
In my case under eclipseLink 2.0, there are A, B and C entity class. A has 1:M relationship to B, B has 1:1 relationship to C. A has PK aId, B has PK aId, bId, C has PK aId and bId, aId is part of PK of B and C, and also FK to A. @Entity class A { @Id @Column(name="A_ID") @GeneratedValue(strategy = GenerationType.AUTO) private String aId; @OneToMany( mappedBy="a", cascade = ALL, targetEntity=B.class) @PrivateOwned private Set bs; } 1. why mappedBy="a" is always complaining that Attribute named "a" has invalid mapping for this relationship. If I removed the @Id in class B for @ManyToOne, this complain will disappear. @Entity class B { @Column(name="B_ID") @Id private int bId; @ManyToOne(cascade = ALL) @JoinColumn(name="A_ID", referencedColumnName="A_ID") @Id @XmlTransient private A a; @OneToOne(optional=false, mappedBy="b", cascade = ALL, targetEntity = C.class) @PrivateOwned private C c; } 1. why mappedBy="b" is always complaining that Attribute named "b" has invalid mapping for this relationship. If I removed the @Id in class C for @ManyToOne, this complain will disappear. But it will compain other thing "Entity "C" has no Id or EmbeddedId" @Entity Class C{ @OneToOne(optional = false) @JoinColumns({ @JoinColumn(name="A_ID", referencedColumnName="A_ID", insertable = false, updatable = false), @JoinColumn(name="B_ID", referencedColumnName="B_ID", insertable = false, updatable = false), }) @XmlTransient @Id private B b; }


View this message in context: Re: Primary key foreign key entity relationship issue
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

Back to the top