How to fetch records using JPQL with case insensitive match

67 views Asked by At

I am trying to fetch the records of employees using JPQL but I don't know name with exact case.

select e from Employee e where e.name = 'rahul'

what changes I need to make in above JPQL to get the list of employee whose name is Rahul, rahul or RAHUL etc.

1

There are 1 answers

0
Sudarshan On

I got a way to fetch the records, though not sure if this is efficient one or not.

TypedQuery<Employee> query = em.createQuery("select e from Employee e where lower(e.name) = :name", Employee.class);
query.setParameter("name", name.toLowerCase());
query.getResultList();