views:

27

answers:

0

This seems to work, but is this the proper way for an entity to have a child set of the same entities?

<hibernate-mapping>
    <class name="com.example.Person" table="Person">
        <id name="id" column="Id" type="int"><generator class="native"/></id>
        <many-to-one name="childOf" class="com.example.Person" column="Child_of_Id"/>
        <set name="children" inverse="true" cascade="save-update" order-by="Id desc">
            <key column="Child_of_Id"/>
            <one-to-many class="com.example.Person"/>
        </set>
    </class>
</hibernate-mapping>

I guess the thing that bothers me is using the same key column name in 2 places and all the references to the same entity. Though the tests pass so far.

related questions