Reputation: 169
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;
@Entity
public class Company implements Serializable {
@Id
@GeneratedValue
private Long id;
private String name;
private String Location;
Upvotes: 0
Views: 2870
Reputation: 24423
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.
Upvotes: 1