Search code examples
javahibernatehql

HQL Like doesn't return anything


Im trying to do a pretty simple HQL query, like I've done times before.

I for some reason fail to find any problems with following query

@Query(value = "FROM SearchCustomer c WHERE c.code =:searchParam OR c.name1 LIKE '%:searchParam%')

and SO threads seem to give same solution, so why is LIKE not returning anything?

Full match c.code works fine. I tried passing in "AAR", "Aar", "aar" to retrieve name1 "AARHUS" but the size of the returned list is always 0.


Solution

  • You need to remove the ' surrounding your %:searchParam%:

    @Query(value = "FROM SearchCustomer c WHERE c.code =:searchParam OR c.name1 LIKE %:searchParam%)