spring-data-jpa onetoone onetomany

OneToOne

@OneToOne
@JoinColumnsOrFormulas(value = {
        @JoinColumnOrFormula(column = @JoinColumn(name = "当前表字段名称", referencedColumnName = "对方表字段名称", nullable = true, insertable = false, updatable = false))
    })

 

OneToMany

@OneToMany
    @JoinColumn(name = "当前表字段名称", referencedColumnName = "对方表字段名称", nullable = true, insertable = false, updatable = false)

或者

one的一方

@OneToMany(mappedBy="xXX", cascade = CascadeType.ALL)

many的一方

@ManyToOne
@JoinColumn(name="当前表外键字段名称")
public XXX getXxx() {
        return xXX;
    }  

 

ManyToOne

@ManyToOne
    @JoinColumnsOrFormulas(value = {
        @JoinColumnOrFormula(column = @JoinColumn(name = "当前表字段名称", referencedColumnName = "对方表字段名称", nullable = true, insertable = false, updatable = false)),
        @JoinColumnOrFormula(formula = @JoinFormula(value = "'值'", referencedColumnName = "对方表其他字段名称")) })

 

你可能感兴趣的:(SpringMVC)