Dept
=====================================================================================
<?xml version="1.0"?>
<!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.jbit.ssh.entity.Dept" table="dept" dynamic-update="true">
<!--配置主键 -->
<id name="deptId" type="java.lang.Integer" column="deptId">
<!--主键生成策略:sequence:oracle的序列,native:看情况 ,assigned:人为给定 identity:自动增长(mysql)increment:用于为 long , short 或 者 int 类型生成 唯一标识 -->
<generator class="identity"/>
</id>
<!-- 属性和列之间的关系 -->
<property name="deptName" type="java.lang.String" column="deptName"/>
<!-- 一对多的映射关系 -->
<set name="emp" cascade="save-update">
<key column="deptId"></key><!-- 外键列 -->
<one-to-many class="cn.jbit.ssh.entity.Emp"/>
</set>
</class>
</hibernate-mapping>
=========================================================================
Emp
=========================================================================
<?xml version="1.0"?>
<!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.jbit.ssh.entity.Emp" table="enploee" lazy="true">
<!--配置主键 -->
<id name="id" type="java.lang.Integer" column="id">
<!--主键生成策略:sequence:oracle的序列,native:看情况 ,assigned:人为给定 identity:自动增长(mysql)increment:用于为 long , short 或者 int 类型生成 唯一标识 -->
<generator class="identity"/>
</id>
<!-- 属性和列之间的关系 -->
<property name="name" type="java.lang.String" column="name"/>
<property name="password" type="java.lang.String" column="password"/>
<!-- 多对一的映射关系 -->
<many-to-one name="dept" column="deptId" class="cn.jbit.ssh.entity.Dept" cascade="save-update" lazy="no-proxy"></many-to-one>
</class>
</hibernate-mapping>