设为首页 加入收藏

TOP

hibernate关联关系-多对一
2014-11-13 23:45:34 来源: 作者: 【 】 浏览:16
Tags:hibernate 关联 关系

  模型:员工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);


  }


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Java加载和实例化以及构造函数 下一篇hibernate关系映射

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: