Hibernate 学习札记(二)——关系映射

具体请点击:http://www.verydemo.com/demo_c146_i18499.html

Hibernate 学习笔记(二)——关系映射
public class Employee {
 
 private int nativeId;
 private String employeeId;
 private String employeeName;
 private String password;
 private Department department;

   getters and setters...

}
public class Department {

 private int nativeId;
 private String departmentId;
 private String departmentName;
 private String departmentinfo;
 private Set<Employee>employeeList;

     getters and setters...

}
<?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 package="wuyechun.studymvc.model">
 <class name="Employee" table="tbl_employee">
         <id name="nativeId">
                <generator class="native"></generator>
       </id>
       <property name="employeeId"></property>
       <property name="employeeName"></property>
       <property name="password"></property>
       <many-to-one name="department" column="departmentId" cascade="save-update"></many-to-one>
  </class>
</hibernate-mapping>
<?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 package="wuyechun.studymvc.model">
 <class name="Department" table="tbl_department">
          <id name="nativeId">
                <generator class="native"></generator>
         </id>
         <property name="departmentId"></property>
         <property name="departmentName"></property>
         <property name="departmentinfo"></property>
        <set name="employeeList" >
              <key column="departmentId"></key>
              <one-to-many class="Employee"/>
        </set>
  </class>
</hibernate-mapping>

相关推荐