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.
@Entity
@Table(name="A")
public class A implements Serializable {

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

}

@Entity
@Table(name="B")
public class B implements Serializable {

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

No comments:

Post a Comment