如何在 Hibernate 中保留递归属性?
我正在努力处理涉及具有相同类类型属性的类的 Hibernate 映射。即(简化):
public class A {
protected A next = null;
}
我的映射当前看起来像:
<hibernate-mapping package="mypackage">
<class name="A" table="tblA" lazy="false">
<id name="id">
<generator class="native"/>
</id>
<property name="next" type="A" />
</class>
</hibernate-mapping>
但是在 Hibernate 初始化期间,我在线程“main”org.hibernate.MappingException 中遇到异常:无法确定类型:A,表:tblA,列:[ org.hibernate.mapping.Column(next)]。
我的理解是,我正在尝试使用尚未声明的映射(因为我现在正在这样做),并且我可能需要诸如前向声明之类的东西。你有什么想法吗?
谢谢
通努兹
I am struggling with a Hibernate mapping involving a class with a property of the same class type. I.e. (simplified):
public class A {
protected A next = null;
}
My mapping currently looks like:
<hibernate-mapping package="mypackage">
<class name="A" table="tblA" lazy="false">
<id name="id">
<generator class="native"/>
</id>
<property name="next" type="A" />
</class>
</hibernate-mapping>
However during Hibernate initialization I get a Exception in thread "main" org.hibernate.MappingException: Could not determine type for: A, at table: tblA, for columns: [org.hibernate.mapping.Column(next)]
.
My understanding is that I am trying to use a mapping which hasn't been declared yet (because I am doing it right now) and I would probably need something like a forward declaration, or so. Do you have any idea?
Thank you
Tunnuz
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它是一个引用:
用于基本类型。通常不需要声明类型,因为它是由 Hibernate 使用反射确定的。It is a reference:
<Property>
is used for primitive types. There is usually no need to declare the type, since it is determined by Hibernate using reflection.