[英]How to get the last value of a column using HQL(Hibernate Query Language)
[英]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;
@Entity
public class Company implements Serializable {
@Id
@GeneratedValue
private Long id;
private String name;
private String Location;
试试这个
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.