一对多表配置文件
Dept(一表)配置
<hibernate-mapping package="cn.yq.b_one2Many">
<class name="Dept" table="t_dept">
<id name="deptId" column="id">
<generator class="native"/>
</id>
<property name="deptName" length="20"/>
<set name="emps" table="t_employee">
<!--俩表中的外键字段-->
<key column="dept_id"/>
<!--Employee类-->
<one-to-many class="Employee"/>
</set>
</class>
</hibernate-mapping>
Employee(多表)配置
<hibernate-mapping package="cn.yq.b_one2Many">
<!--在一对多中外键只有一个就是多方的外键-->
<class name="Employee" table="t_employee">
<id name="empId" column="id">
<generator class="native"/>
</id>
<property name="empName" length="20"/>
<property name="salary" type="double"/>
<!--dept:Employee实体中的属性 column:俩表中的外键字段 class:Dept(一)类-->
<many-to-one name="dept" column="dept_id" class="Dept"/>
</class>
</hibernate-mapping>
-----------------------------------------------------------------------------------

976D1029-AAD9-4356-8EFC-E741096F5600.png
80526562-BF87-4426-943F-FE52B8A2FECB.png