我可以在HBM映射中执行以下操作吗?
<class name="Employee" table="employees">
<!-- assume that each person only has exactly one supervisor -->
<many-to-one name="supervisor" class="Employee" column="supervisorId" />
</class>
当我使用上面的HBM映射时,我的服务器拒绝启动以下错误:
org.hibernate.InstantiationException: could not instantiate test object Employee
Caused by: java.lang.StackOverflowError
at Employee.<init>(Employee.java:11)
at Employee.<init>(Employee.java:11)
at Employee.<init>(Employee.java:11)
...... (about a hundred duplicates)
Employee.java的第11行只是说:
public class Employee implements Serializable {
我应该如何建立我的主管 - 员工关系模型?主管没有特殊的POJO,主管对象没有特殊字段。
答案 0 :(得分:1)
Hibernate应该没有映射这种关系的问题。
看起来无限递归是由代码中的错误引起的,如下所示:
public class Employee {
private Employee supervisor = new Employee();
}