顾客与订单关系中的订单的映射文件:
多对一
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--顾客与订单关系中,订单的映射文件-->
<class name="com.ssii.pojo.Order" table="order">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<!--普通属性-->
<property name="address" column="address" length="50"/>
<property name="price" column="price"/>
<!--多对一关系映射-->
<many-to-one name="customer" class="cn.itcast.Customer" column="cid"></many-to-one>
<!--name属性用来描述customer在Order类中的属性名,class属性用来指定映射的类,
column属性值对应表中的外键列名.
-->
</class>
</hibernate-mapping>
顾客与订单关系中的顾客的映射文件:
一对多
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--顾客与订单关系中,顾客的映射文件-->
<class name="cn.itcast.Customr" table="customer">
<id name="id" column="id">
<generator class="native "></generator>
</id>
<!--配置普通属性-->
<property name="name" column="name" length="20"></property>
<!--一对多的关系使用set集合映射-->
<set name="order">
<!--确定关联关系的外键列,与其对应的多对一中的column属性值相同 -->
<key column="cid"/>
<one-to-many class="cn.itcast.Order"/>
</set>
</class>
</hibernate-mapping>
<–*********************************************************************************************************–>
学生与课程中的多对对关系
Student.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--多对多关系-->
<class name="cn.itcast.Student" table="student">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<!--普通属性-->
<property name="sname" length="30"></property>
<!--多对多关系-->
<set name="courses" table="s_c">
<key column="sid"></key>
<many-to-many class="cn.itcast.Course" column="cid" ></many-to-many>
</set>
<!-- table 表示中间表的名称,也就是说指定创建student表时生成的外键放在哪张表里,
key标签的column属性用于描述studen表在中间表中外键列名称
many-to-many标签的column属性用于描述course在中间表中的列名 -->
</class>
</hibernate-mapping>
Course.hbm.xml
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--多对多关系-->
<class name="cn.itcast.Course" table="course">
<id name="id" column="id">
<generator class="native"></generator>
</id>
<property name="cname" length="30"></property>
<set name="students" table="s_c">
<key column="cid"></key>
<many-to-many class="cn.itcast.Student" column="sid"></many-to-many>
</set>
</class>
</hibernate-mapping>