hibernate单表一对多如何实现?
我现在一张产品类别表结构如下
id name parent
我想利用这张表配置一个一对多关系。如何配置,谢谢。
------解决方案--------------------
试试把单表看作两个表,然后配置两个类
用一个类可能会造成死循环
------解决方案--------------------
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 2008-8-29 14:16:14 by Hibernate Tools 3.2.0.b9 -->
<hibernate-mapping>
<class name="com.tradeserving.right.model.Menus" table="menus" >
<id name="id" type="int">
<column name="id" />
<generator class="increment" />
</id>
<many-to-one name="parentMenu" column="pid" class="com.tradeserving.right.model.Menus" />
<set name="children" cascade="save-update" inverse="true" lazy="false">
<key column="pid" />
<one-to-many class="com.tradeserving.right.model.Menus" />
</set>
<property name="text" type="string">
<column name="text" />
</property>
<property name="href" type="string">
<column name="href" />
</property>
<property name="hrefTarget" type="string">
<column name="hrefTarget" length="100" />
</property>
<property name="sort" type="integer">
<column name="sort" />
</property>
</class>
</hibernate-mapping>
单表的tree
------解决方案--------------------自关联应该是你想要的