繁体   English   中英

如果一列中没有空值,则无法获取行

[英]Not able to get the row if there is null value in one column hibernate hql

我在搜索操作中遇到困难。 如果一行的一列中有任何null值,则该行不会出现。 我尝试在hql使用is not null ,但无法获取值。 我已经写了这样的hql查询。 它什么也没返回。 我无法理解它的工作方式。 请告诉我该解决方案。 我正在使用mysql

session.createQuery("FROM Employee e WHERE (e.company is not null and e.company.name = :p1) or e.name = :p1").setParameter("p1", str)

我的@Entity类是这些:

@Entity
public class Employee implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    private String name;
    private float salary;

    @OneToOne(cascade = CascadeType.ALL)
    private Company company;

数据库中<code> Employee </ code>的数据

@Entity
public class Company implements Serializable {

    @Id
    @GeneratedValue
    private Long id;
    private String name;
    private String Location;

<code> Company </ code>表的数据

试试这个

session.createQuery("FROM Employee e left join e.company c WHERE c.name = :p1 or e.name = :p1").setParameter("p1", "uday11")

在查询中使用e.company ,它会转换为inner join ,这就是为什么它无法按预期工作的原因。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM