Day02:

作者: 宇宙超人喵学长 | 来源:发表于2017-07-13 14:41 被阅读0次
    • 1、 Identifiers

    UNIQUE:每行唯一
    NOT NULL:
    IMMUTABLE:once inserted, can never be changed

    • 2、GenerationType生成值

    AUTO(默认):表示持久性提供程序(Hibernate)应选择适当的生成策略
    IDENTITY:表示数据库IDENTITY列将用于生成主键值
    SEQUENCE:表示数据库序列应用于获取主键值
    TABLE:表示应使用数据库表获取主键值

    隐式使用UUID策略
    @Id
    @GeneratedValue( generator = "uuid" )
    @GenericGenerator(
    name = "uuid",
    strategy = "org.hibernate.id.UUIDGenerator",
    parameters = {
    @Parameter(
    name = "uuid_gen_strategy_class",
    value = "org.hibernate.id.uuid.CustomVersionOneStrategy"
    )
    }
    )
    public UUID id;

    • 3、关系映射

    父方:
    @OneToMany(mappedBy = "person", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<Phone> phones = new ArrayList<>();
    @OneToOne(mappedBy = "phone", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    private PhoneDetails details;
    子方:
    @ManyToOne
    private Person person;
    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "phone_id")
    private Phone phone;

    • 4、集合

    两个实体不能共享同一个集合的引用
    集合值属性不支持空值语义(hibernate不区分空集合和空集合引用)

    • 5、NaturalIdLoadAccess 自然编号

    API:load()获取对实体的引用(该实体已初始化)
    getReference():获取引用
    @NaturalId(mutable=true):默认为不可改,mutable=true时可变

    • 5、继承

    父实体@MappedSuperclass:在域模型中体现,不在数据库模式中反应,不支持多态查询
    single table:@Inheritance(strategy = InheritanceType.SINGLE_TABLE),所有子类映射到同一个数据库表,每个子类必须定义唯一的标识符值,所以查询效率最高,只需单表
    Joined table:@Inheritance(strategy = InheritanceType.JOINED)每个类有自己的表,超类表关联关系。该表主键为超类表的外键,该表@PrimaryKeyJoinColumn(name = "account_id")设置外键
    Table per class:@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS),各存各的,考虑多态关联,使用union

    相关文章

      网友评论

          本文标题:Day02:

          本文链接:https://www.haomeiwen.com/subject/lfjwhxtx.html