@Where子句不适用于@ManyToOne

时间:2020-09-24 16:12:00

标签: spring jpa spring-data-jpa hibernate-mapping

我有一个父实体,必须在其中使用@ManyToOne加入子实体。我想在@Where中使用@ManyToOne子句。 Hibernate查询未考虑@Where子句。 有什么解决方法吗? 我还在子实体级别提供了@Where子句,但没有用

public class Employee() { 
    @Id   
    @Column(name = "Emp_id")    
    private Integer empId;

    @Column(name = "cmp_id")   
    private Integer cmpId;

    @ManyToOne  
    @JoinColumn(name = "cmp_id", referencedColumnName = "cmp_id", insertable = false, updatable = false)   
    @Where(clause = "cmp_cl_id =1")  
    private Student student ;  
}

public class Student() {  
    @Id   
    @Column(name = "cmp_id")  
    private Integer cmpId;

    @Column(name = "cmp_cl_id ")  
    private Integer cmpClId ;  
}

0 个答案:

没有答案