【发布时间】:2012-04-16 10:38:45
【问题描述】:
使用 Hibernate 和 JPA,我想映射一个包含其自身对象列表的类,例如:
public class Category{
private List<Category> subCategories = new ArrayList<Category>();
}
我正在尝试使用:
@OneToMany(fetch = FetchType.EAGER, mappedBy = "category")
但是当我尝试这个时,我得到以下错误:
Initial SessionFactory creation failed.org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: my.domain.name.Category.category in my.domain.name.Category.subCategories
【问题讨论】:
-
你想做的叫做“自引用实体”。看看这个答案:stackoverflow.com/a/3393662/870122
-
是的,这正是我的情况,但我现在收到此错误: Initial SessionFactory creation failed.org.hibernate.HibernateException: Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
标签: java hibernate jakarta-ee jpa