递归 HBM 映射
我可以在 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,并且主管对象没有特殊字段。
Can I do the following in my HBM mapping?
<class name="Employee" table="employees">
<!-- assume that each person only has exactly one supervisor -->
<many-to-one name="supervisor" class="Employee" column="supervisorId" />
</class>
When I use the above HBM mapping, my server refuses to start with the following error:
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)
line 11 of Employee.java merely says:
public class Employee implements Serializable {
How should I model my supervisor-employee relationship? There is no special POJO for supervisor and supervisor objects have no special fields.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Hibernate 在映射这种关系时不应该有问题。
看起来无限递归是由代码中的错误引起的,如下所示:
Hibernate shouldn't have a problem with mapping such a relationship.
It looks like infinite recursion is caused by error in your code, something like this: