提示:
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;
}
}