Primary Key and one-to-may relatuioship [message #389796] |
Tue, 07 July 2009 11:08  |
Eclipse User |
|
|
|
Dear all,
can be a property both an @id and the field for @onetomany relatioship.
An example can be more clear:
I have two Entity: A and B. A entity is related to many B entities.
@Entity
@Table(name="APP.CFG")
public class A implements {
int id;;
//jpa relationship
private List<B> Bs;
@Id
public int getId() {
return id;
}
................
@OneToMany(cascade=CascadeType.ALL,
mappedBy="a",fetch=FetchType.LAZY)
public List<B> getBs() {
return Bs;
}
......
}
@IdClass(BPK.class)
@Entity
public class B {
private id;
private A a;
@Id
public int getId() {
return id;
}
@Id
@ManyToOne
@JoinColumn(name="a", nullable=false)
public A getA() {
return a;
}
......
}
So, Entity B has a composite-key (but can an entity be a fied of a
primary key?or can i have only primitive types?) and one of its field
(a) is both @id and also @manytoone.
Is this possible?I get always the following error:
AN INCOMPATIBLE MAPPING HAS BEEN ENCOUNTERED BETWEEN [CLASS A] AND
[CLASS B]. THIS USUALLY OCCURS WHEN THE CARDINALITY OF A MAPPING DOES
NOT CORRESPOND WITH THE CARDINALITY OF ITS BACKPOINTER.
Thanks in advance,
Enrico
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.18131 seconds