0

I am trying to write a JPQL query for searching data based on String. when i am trying to search data with 'C' it works fine, but its not working for 'c', below is the query. for example: below query is working for Cat, College, Collapse, but not working for cat, college, collapse. any help is appreciate.

@Query("select ca.company_01 from CompanyAddress_02 ca WHERE ca.statusActiveSwitch = 'Y' AND ca.country.region.regionCode = :regionCode")
    Page<Company_01> findAllCompany_01Region(@Param("regionCode") String regionCode,  Pageable pageRequest);

1 Answers1

2

One approach would be to just lowercase both sides of the region code when comparing in your JPQL query:

@Query("SELECT ca.company_01 FROM CompanyAddress_02 ca WHERE ca.statusActiveSwitch = 'Y' AND LOWER(ca.country.region.regionCode) = LOWER(:regionCode)")
Page<Company_01> findAllCompany_01Region(@Param("regionCode") String regionCode,  Pageable pageRequest);

Note that if you don't really have any use for the case in your region code, then consider just storing it all in a one case, e.g. lowercase, and then ensure that what you pass to your backend is also always the same case. This avoids calling LOWER(), which renders the WHERE clause non sargable (i.e. it cannot use an index).

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360