Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Primary Key and one-to-may relatuioship
Primary Key and one-to-may relatuioship [message #389796] Tue, 07 July 2009 11:08 Go to previous message
Enrico is currently offline Enrico
Messages: 82
Registered: July 2009
Member
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
 
Read Message
Read Message
Read Message
Read Message
Previous Topic:Eclipselink with OSGi
Next Topic:Thrown exceptions are useless
Goto Forum:
  


Current Time: Wed May 22 01:02:02 EDT 2013

Powered by FUDForum. Page generated in 0.05097 seconds