I have a entity as below
JavaScript
x
public class Employee implements Serializable {
@Id
@Column(name = "EMPSEQ")
@GeneratedValue(strategy = GenerationType.AUTO)
private Long empSeq;
@Column(name = "EMPID")
private String empId;
@Column(name = "WINDOWSLOGINID")
private String logInId;
// assume respective getter and setter methods
}
I want to query all row where logInId does not start with “5”
I tried below code:
JavaScript
query = session.createQuery("select * from Employee e where e.logInId not like 5%");
the above code didn’t work. what is the right way to use NOT LIKE
in HQL
Advertisement
Answer
In your query there’s an error:
JavaScript
query = session.createQuery("select * from Employee e where e.logInId not like 5%");
become:
JavaScript
query = session.createQuery("select * from Employee e where e.logInId not like '5%'");
e.logInId
is string, so you must quote your condition 5%.