Search code examples
hibernatenamed

Named Query Hibernate


I have a query something like this

select emp from EMP emp where emp. empno like :emp_var and emp. empname like : empname_var and emp. empDate = :empdate_var

In the above query, all the three named parameters might not null or atleast one parameter will be not null and other might be null. In other words, I might retrieve only by empname or empDate or empno, or, by empname and empno and empdate.

How to achieve this in Hibernate


Solution

  • You will need to check your values and add them to the Criteria as needed using Restrictions.

    You can also look into using Example.