hibernate<7>----继承关系映射
Department.java
Employee.hbm.xml 子类的部分在父类的表中,但子类有自己的表
Employee.hbm.xml 一个子类的部分在父类的表中,一个子类的全部在父类中
Employee.hbm.xml 子类和父类都在单独的表中
hibernate.cfg.xmlpackage cn.anycall.hibernate;import java.util.HashSet;import java.util.Set;import org.hibernate.Session;import org.hibernate.Transaction;import cn.anycall.hibernate.domain.Department;import cn.anycall.hibernate.domain.Employee;import cn.anycall.hibernate.domain.Sales;import cn.anycall.hibernate.domain.Skiller;public class Extends {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubDepartment depart = add();query(3);}static Department add(){Session s = null;Transaction tx = null;try{s = HibernateUtil.getSession();tx = s.beginTransaction();Department depart = new Department();depart.setName("depart name");Employee emp = new Employee();emp.setDepart(depart);emp.setName("employee name");Skiller sk = new Skiller();sk.setDepart(depart);sk.setName("employee skill");sk.setSkill("skill");Sales sa = new Sales();sa.setDepart(depart);sa.setName("employee sales");sa.setSell(2);Set<Employee> set = new HashSet<Employee>();set.add(sa);set.add(emp);set.add(sk);depart.setEmp(set);s.save(emp);s.save(sa);s.save(sk);s.save(depart);tx.commit();System.out.println("end");return depart;}finally{if(s!=null)s.close();}}static void query(int id){Session s = null;try{s = HibernateUtil.getSession();Employee em = (Employee) s.get(Employee.class, id);System.out.println("end");System.out.println(em.getClass());//Hibernate.initialize(depart.getEmp());}finally{if(s!=null)s.close();}}}