模型:员工Employee ― 部门Department
Java代码
package Domain;
public class Employee {
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Department getDepart() {
return depart;
}
public void setDepart(Department depart) {
this.depart = depart;
}
private int id;
private String name;
private Department depart;
}
Java代码
package Domain;
import java.util.Set;
public class Department {
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Set<Employee> getEmps() {
return emps;
}
public void setEmps(Set<Employee> emps) {
this.emps = emps;
}
private int id;
private String name;
private Set<Employee> emps ;
}
Xml代码
<?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="Domain">
<class name="Employee" table="employee">
<id name="id">
<generator class="native" />
</id>
<property name="name" unique="true"/>
<many-to-one name="depart" column="depart_id"/>
</class>
</hibernate-mapping>
Xml代码
<?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="Domain">
<class name="Department" table="department">
<id name="id">
<generator class="native" />
</id>
<property name="name" unique="true"/>
<set name="emps">
<key column="depart_id"/>
<one-to-many class="Employee"/>
</set>
</class>
</hibernate-mapping>
Java代码
package Dao;
import Domain.Employee;
public interface EmployeeDAO {
public void saveEmployee(Employee emp);
public Employee findEmployeeByName(String name);
public Employee findEmployeeById(int id);
public void updateEmployee(Employee emp);
public void removeEmployee(Employee emp);
}