Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Composite foreign primary key in 3 tables

Hello, 

I have three tables:

Table A:
id (PK)

Table B:
aid (FK from A, PK)
num (PK)

Table C:
aid (FK from A, PK)
bnum (FK from B, PK)
time (PK)


With eclipselink i have annotated the ManyToOne-relation from B to A as
follows:
@Entity
public class A {
 @Id
 public int id;
}

@IdClass (BPK.class)
@Entity
public class B {
 @Id
 @ManyToOne
 @JoinColumn (name="aid" referencedColumnName="id")
 public A a;

 @Id
 public int num;
}

With BPK as the IdClass containing a and num.

This does work as intended!

For table C I annotated the ManyToOne-relation from C to B as follows:

@IdClass (CPK.class)
@Entity
public class C {
 @Id
 @ManyToOne
 @JoinColumns ({ @JoinColumn (name="aid", referencedColumnName="aid"),
@JoinColumn(name="bnum", referencedColumnName="num") })
 public B b;

 @Id
 public int time;
}

With CPK being the IcClass containing B and time.

When I try to run this I get an error:
org.eclipse.persistence.exceptions.ValidationException
Exception Description: The composite primary key attribute [b] of type
[null] on entity class [class C] should be of the same type as defined on
its primary key class [CPK]. That is, it should be of type [B].

I don't get it why the type of b is null. Obviously it is not.

Am I missing out anything?

Thanks for replying.
-- 
View this message in context: http://old.nabble.com/Composite-foreign-primary-key-in-3-tables-tp28972870p28972870.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top