Hibernate collection mapping challenge

Posted by Geln Yang on Stack Overflow See other posts from Stack Overflow or by Geln Yang
Published on 2010-05-21T17:09:22Z Indexed on 2010/05/21 17:10 UTC
Read the original article Hit count: 265

Hi,

There is a table Item like,

code,name
01,parent1
02,parent2
0101,child11
0102,child12
0201,child21
0202,child22

Create a java object and hbm xml to map the table.The Item.parent is a Item whose code is equal to the first two character of its code :

class Item{
    string code;
    string name;
    Item parent;
    List<Item> children;

    .... setter/getter....

}

<hibernate-mapping>
    <class name="Item" table="Item">
        <id name="code" length="4" type="string">
            <generator class="assigned" />
        </id>
        <property name="name" column="name" length="50" not-null="true" />
        <!--====================================== -->
       <many-to-one name="parent" class="Item" not-found="ignore"></many-to-one>
        <bag name="children"></bag>
            <!--====================================== -->

    </class>

</hibernate-mapping>

How to definition the mapping relationship? Thanks!

© Stack Overflow or respective owner

Related posts about hibernate

Related posts about java