Hibernate关系映射

1.一对多,多字段

@JsonIgnore
    @OneToMany(mappedBy = "abc",cascade={CascadeType.PERSIST},fetch=FetchType.LAZY)
    private Set<Entity> entity;
@ManyToOne(optional = true,fetch = FetchType.LAZY)
    @JoinColumnsOrFormulas(value={
    @JoinColumnOrFormula(column=@JoinColumn( name = "id" ,referencedColumnName = "id" ,insertable =false, updatable = false)),
    @JoinColumnOrFormula(column=@JoinColumn( name = "tid" ,referencedColumnName = "tid" ,insertable =false, updatable = false))})
    private ABC abc;

2.一对一,多字段

@JsonIgnore
    @OneToOne(optional = true,fetch = FetchType.LAZY)
    @JoinColumns(value={
            @JoinColumn(name="id",referencedColumnName="id",insertable =false, updatable = false),
            @JoinColumn(name="uid",referencedColumnName="uid",insertable =false, updatable = false)})
    private Entity entity;

 

posted @ 2017-06-26 16:05  margin_gu  阅读(313)  评论(0编辑  收藏  举报