[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.rt.eclipselink] Primary Key and one-to-may relatuioship

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