Skip to main content

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

Hello,

The specification states you should have A's id within the BPK class, not A itself. The same goes for CPK, it should contain int time and BPK b as attributes. Please feel free to file a bug to have the error message improved if changing this resolves the problem.

Best Regards,
Chris

On 24/06/2010 3:15 AM, Horat wrote:
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.


Back to the top