glocalor
glocalor
2015-03-12 15:43

使用JPA @ManyToMany做双向关联时mappedBy报错

  • jboss
  • jpa

提示:
In attribute 'testA', the "mapped by" attribute 'testB' has an invalid mapping type for this relationship.

代码如下:
@Entity(name="testa")
public class TestA {
Long id;
List testB=new ArrayList();
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@OneToMany(cascade = {CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinTable( name="TESTA_TESTB", //中间表名
joinColumns=@JoinColumn(name="TESTA_ID"),
inverseJoinColumns=@JoinColumn(name="TESTB_ID"))
public List getTestB() {
return testB;
}
public void setTestB(List testB) {
this.testB = testB;
}

}
实体B
@Entity(name="testb")
public class TestB {
Long id;
List testA=new ArrayList();
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@ManyToMany(mappedBy = "testB")
public List getTestA() {
return testA;
}
public void setTestA(List testA) {
this.testA = testA;
}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答