首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

Hibernate 联系关系映射

2012-09-19 
Hibernate 关联映射Hibernate 关联映射hibernate-mapping??? class namecom.pojo.Itemtableitem

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>

?

?

热点排行