Hibernate oneToOne加入其他标准

时间:2016-10-06 09:24:33

标签: java mysql spring hibernate

我需要在hibernate中进行连接,但是我想从被发现中排除一些结果。我已尝试使用@JoinColumnsOrFormulas,但我仍然可以获得所有结果

@OneToOne
@JoinColumnsOrFormulas({
        @JoinColumnOrFormula(formula = @JoinFormula(value= "(select a.seller_sku from de_products a where a.asin = 'a' and a.product_name != '' and a.seller_sku != '' and a.seller_sku = sku)", referencedColumnName = "seller_sku")),
        @JoinColumnOrFormula(column = @JoinColumn(name = "sku", referencedColumnName = "seller_sku", insertable = false, updatable = false))
})
public DeProducts getDeProduct() {
    return deProduct;
}

如果我在没有column定义的情况下尝试

@OneToOne
@JoinColumnsOrFormulas({
        @JoinColumnOrFormula(formula = @JoinFormula(value= "(select a.seller_sku from de_products a where a.asin = 'a' and a.product_name != '' and a.seller_sku != '' and a.seller_sku = sku)", referencedColumnName = "seller_sku"))
})
public DeProducts getDeProduct() {
    return deProduct;
}

我在应用程序启动时遇到NullPointerException,位于

  

org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory

如何使用spring-boot(1.4)hibernate(5.2.2.Final)与其他标准/排除项进行联接?

1 个答案:

答案 0 :(得分:0)

我想我找到了一个有效的解决方案。在引用公式和@JoinColumn注释中的相同列时,Hibernate似乎忽略了@JoinForumula。当引用公式中的另一列时 - 例如id,它有效。

@OneToOne
@JoinColumnsOrFormulas({
        @JoinColumnOrFormula(formula = @JoinFormula(value = "(select a.id from de_products a where a.asin != '' and a.product_name = 'a' and a.seller_sku = sku)", 
              referencedColumnName = "id")),
        @JoinColumnOrFormula(column = @JoinColumn(name = "sku", referencedColumnName = "seller_sku", insertable = false, updatable = false))
})
public DeProducts getDeProduct() {
    return deProduct;
}