Hibernate Annotations自引用类? [英] Hibernate Annotations self referencing class?
本文介绍了Hibernate Annotations自引用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经定义了这个Entity类,但是它似乎没有将子级保存到数据库中.有任何想法吗?
I have defined this Entity class, but it does not seem to save the children to the database. Any ideas?
@Entity
public class CategoryModel implements Model<CategoryModel>, Serializable {
private static final long serialVersionUID = -4520507504770029807L;
@Id
@Field(index = Index.UN_TOKENIZED, store = Store.NO)
private String id;
@NotNull
private String name;
@ManyToOne
private CategoryModel parent;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
private List<CategoryModel> children;
public List<CategoryModel> getChildren() {
return children;
}
public String getId() {
return id;
}
public String getName() {
return name;
}
public CategoryModel getParent() {
return parent;
}
public void setChildren(List<CategoryModel> children) {
this.children = children;
}
public void setId(String id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setParent(CategoryModel parent) {
this.parent = parent;
}
}
非常感谢, Finbarr
Many thanks, Finbarr
推荐答案
这是因为反向关联从不持久;我可以说这是"mappedBy"属性的反向关联
That's because the reverse association is never persisted; I can tell this is the reverse association beacause of the "mappedBy" attribute
这篇关于Hibernate Annotations自引用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文