Single Table策略 通过 discriminator鉴别器来区分是父类还是子类 Employee public class Employee { private Long id; private String name; HourlyEmployee public class HourlyEmployee extends Employee { private Double rate; SalariedEmployee public class SalariedEmployee exte…
工程截图 hibernate.cfg.xml <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factor…
Employee public class Employee { private Long id; private String name; HourlyEmployee public class HourlyEmployee extends Employee { private Double rate; SalariedEmployee public class SalariedEmployee extends Employee { private Double salary; Employe…
Employee public class Employee { private Long id; private String name; HourlyEmployee public class HourlyEmployee extends Employee { private Double rate; SalariedEmployee public class SalariedEmployee extends Employee { private Double salary; Employe…
ddl语句 CREATE TABLE `t_user` ( `id` varchar(32) NOT NULL, `name` varchar(255) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; User package com.jege.jpa.primary; import javax.persistence.Column; import javax.persistence.Entity; i…
双向一对一 一对一主要用在 一个一方需要的信息比较少,比如注册的登录信息 另一个一方存储的信息比较多,比如注册之后用户填写的详细信息 实现方式常用的主要有2种: java模型都是一样,其中一个映射文件有所不同 hibernate.cfg.xml <mapping resource="com/jege/hibernate/two/way/onetoone/User.hbm.xml" /> <mapping resource="com/jege/hibernat…
Employee public class Employee { private Long id; private String name; HourlyEmployee public class HourlyEmployee extends Employee { private Double rate; SalariedEmployee public class SalariedEmployee extends Employee { private Double salary; Employe…
组成关系 在一个员工模型里面需要存入 员工公司所在地址的城市,街道 员工籍贯所在的城市,街道, 此时可以抽取城市,街道变成一个模型即是组成关系 Employee public class Employee { private Long id; private String name; // 公司的地址 private Address comAddress; // 籍贯所在地 private Address homeAddress; Employee.hbm.xml <class name="…
自关联:本质还是原来双向一对多,原来要配置两个类,现在全部都配置在一个类里面 Employee public class Employee { private Long id; private String name; // 多对一: 多个员工对一上级 private Employee manager; // 一对多:一个领导有多个下级 private Set<Employee> children = new HashSet<Employee>(); Employee.hbm.xm…
复合主键 复合主键的意思就是2个字段同时为主键 不使用无业务含义的自增id作为主键 Airline package com.jege.hibernate.compositeid; import java.io.Serializable; //使用复合主键的持久化类需要实现serializable接口和覆盖equals().hashCode()方法. public class Airline implements Serializable{ private String startCity; pr…