0

我可以在我的 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,主管对象没有特殊字段。

4

1 回答 1

1

Hibernate 应该没有映射这种关系的问题。

看起来无限递归是由代码中的错误引起的,如下所示:

public class Employee {
    private Employee supervisor = new Employee();
}
于 2011-05-03T16:05:29.087 回答