Issue
I have a entity as below
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:
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
Solution
In your query there's an error:
query = session.createQuery("select * from Employee e where e.logInId not like 5%");
become:
query = session.createQuery("select * from Employee e where e.logInId not like '5%'");
e.logInId
is string, so you must quote your condition 5%.
Answered By - Joe Taras
Answer Checked By - Mary Flores (JavaFixing Volunteer)