简体   繁体   English

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

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

I'm having difficulties in search operation. 我在搜索操作中遇到困难。 If there is any null value in a column of one row then that row is not coming. 如果一行的一列中有任何null值,则该行不会出现。 I tried using is not null in hql , but I'm not able get the values. 我尝试在hql使用is not null ,但无法获取值。 I have written hql query like this. 我已经写了这样的hql查询。 It is returning nothing. 它什么也没返回。 I'm not able to understand how it is working. 我无法理解它的工作方式。 Please tell me the solution for this one. 请告诉我该解决方案。 I'm using mysql . 我正在使用mysql

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

My @Entity classes are these: 我的@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>表的数据

Try with this 试试这个

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

When you use e.company in your query it is translated to inner join , that's why it is not working as expected. 在查询中使用e.company ,它会转换为inner join ,这就是为什么它无法按预期工作的原因。

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

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