当值为null时如何避免@JoinColumn的休眠SELECT

时间:2018-07-05 14:32:12

标签: java hibernate

我在休眠状态@ManyToOne中有一个关系定义为

@Entity
@Table(name = "OD_STOCK")
public class Stock {

  @ManyToOne(fetch = FetchType.LAZY)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumnsOrFormulas({@JoinColumnOrFormula(column = @JoinColumn(name = "NBCHSQUALITYCHECKID", referencedColumnName = "GD_CODEID")),
            @JoinColumnOrFormula(formula = @JoinFormula(referencedColumnName = "GD_CODETYPE", value = "'NBCHSQUALITYCHECK'"))})
    private NBCHealthAndSafetyQualityCheck nbcHealthAndSafetysQualityCheck;

}

NBCHSQUALITYCHECKID列在表OD_STOCK上,并且在某些记录中为空,但是当我读取该记录时,使用另一个NULL值对其他表进行了不必要的SELECT。不需要此选择,因为JOIN的COLUMN为NULL

当MASTER表中的JOIN COLUMN为NULL时,如何避免休眠进行SELECT?

我已经针对此问题对Hibernate进行了改进:

https://hibernate.atlassian.net/browse/HHH-12770

谢谢!

0 个答案:

没有答案