我正在关注this tutorial以使JPA与EJB3.0一起工作
package example.pojo;
@Entity
public class Cat {
private String name;
private Date birthDate;
private int id;
private Cat mother;
private List kittens;
public Cat() {
super();
setKittens(new ArrayList());
}
@ManyToOne(optional = true)
public Cat getMother() {
return mother;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "mother", targetEntity = example.pojo.Cat)
public List getKittens() {
return kittens;
}
@Id @GeneratedValue(strategy = GenerationType.AUTO)
public int getId() {
return id;
}
}
我想在同一个实体中建立两个属性之间的关系,但这里的映射不起作用。请向我解释我做错了什么以及如何解决这个问题。
您必须将该实体放在persistence.xml
标签区域的persistence-unit
中,如:
<persistence-unit>
<class>samplePackage.Cat</class>
</persistence-unit>
当你添加它时,它将被修复