Friday, 11 November 2011

JPA error: "Use of @OneToMany or @ManyToMany targeting an unmapped class"

Possible reason 2: target

I had two classes with bi-directional @ManyToMany relationship.
They both return Sets i.e. Generics therefore I have to set
target. But I did the mistake to set it to Set but they right
was setting it to the types of the elements the Sets include.
public class A implements Serializable {

 //@ManyToMany(...,targetEntity=Set.class) //wrong
 @ManyToMany(...,targetEntity=A.class) //right
 public Set getManyB(){...}


public class B implements Serializable {

 @ManyToMany(...,targetEntity=Set.class) //wrong
 @ManyToMany(...,targetEntity=A.class) //right
 public Set getManyA(){...}

No comments:

Post a Comment