[英]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;
@Entity
public class Company implements Serializable {
@Id
@GeneratedValue
private Long id;
private String name;
private String Location;
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.