简体   繁体   English

如何在Hibernate中保留递归属性?

[英]How to persist a recursive property in Hibernate?

I am struggling with a Hibernate mapping involving a class with a property of the same class type. 我正在努力尝试一个涉及具有相同类类型属性的类的Hibernate映射。 Ie (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)] . 但是,在Hibernate初始化期间,我Exception in thread "main" org.hibernate.MappingException: Could not determine type for: A, at table: tblA, for columns: [org.hibernate.mapping.Column(next)]得到了一个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 Tunnuz

It is a reference: 它是一个参考:

<many-to-one name="next"/>

<Property> is used for primitive types. <Property>用于基本类型。 There is usually no need to declare the type, since it is determined by Hibernate using reflection. 通常不需要声明类型,因为它是由Hibernate使用反射确定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM