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…
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…
在二级缓存配置成功的基础上进行查询缓存配置 Product public class Product { private Long id; private String name; Product.hbm.xml <class name="Product"> <id name="id"> <generator class="native" /> </id> <property name=&qu…
pom.xml <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-ehcache</artifactId> <version>${hibernate.version}</version> </dependency> Product /** * @author JE哥 * @email 1272434821@qq.com * @…
Product public class Product { private Long id; private String name; Product.hbm.xml <class name="Product"> <id name="id"> <generator class="native" /> </id> <property name="name" /> &l…
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…
组成关系 在一个员工模型里面需要存入 员工公司所在地址的城市,街道 员工籍贯所在的城市,街道, 此时可以抽取城市,街道变成一个模型即是组成关系 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…