Hibernate collection mapping challenge
- by Geln Yang
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!