Hibernate 关联映射
Hibernate 关联映射
<hibernate-mapping>
??? <class name="com.pojo.Item"table="item" catalog="gdev">
??????? <id name="itemId"type="java.lang.Integer">
??????????? <column name="itemid"/>
??????????? <generator class="sequence">
??????????? <param name="sequence">sequence_ip_info</param>
??????????? </generator>
??????? </id>
??????? <property name="itemName"type="java.lang.String">
??????????? <column name="itemname"length="32" not-null=”true”/>
??????? </property>
??????? <property name="itemCode"type="java.lang.String">
??????????? <column name="itemcode”? length=”32” not-null=”true”/>
??????? </property>
???? </class>
</hibernate-mapping>
<hibernate-mapping>
??? <class name="com.pojo.SubItem"table="subitem" catalog="gdev">
??????? <id name="subId"type="java.lang.Integer">
??????????? <column name="subid"/>
??????????? <generator class="sequence">
??????????? <param name="sequence">sequence_ip_info</param>
??????????? </generator>
??????? </id>
??????? <property name="subName"type="java.lang.String">
??????????? <column name="subname"length="32" not-null=”true”/>
??????? </property>
??????? <property name="subCode"type="java.lang.String">
??????????? <column name="subcode”? length=”32” not-null=”true”/>
??????? </property>
<many-to-one name="item"column=”itemid” class=”com.pojo.Item”/>
???? </class>
</hibernate-mapping>
?
注解:<many-to-one>元素建立了item属性和subitem表的外键itemid的映射关系,实现了可以通过many方得到one方相关的数据。
<key column=”teaid”/>
<many-to-manyclass=”com.hibernate3.pojo.student” column=”stuid”/>
<key column=”stuid”/>
<many-to-manyclass=”com.hibernate3.pojo.Teacher” column=”teaid”/>
</set>
?
?