简体   繁体   中英

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. I tried using is not null in hql , but I'm not able get the values. I have written hql query like this. 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 .

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
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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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