hibernate关联关系-多对一

2014-11-13 23:45:34 · 作者: · 浏览: 19

  模型:员工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 getEmps() {


  return emps;


  }


  public void setEmps(Set emps) {


  this.emps = emps;


  }


  private int id;


  private String name;


  private Set emps ;


  }


  Xml代码


  


  


  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"


  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


  


  


  


  


  


  


  


  


  


  Xml代码


  


  


  "-//Hibernate/Hibernate Mapping DTD 3.0//EN"


  "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">


  


  


  


  


  


  


  


  


  


  


  


  


  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);


  }