Is it possible to have a like in a where clause in a named query? I am trying to do the following but am getting exceptions
@NamedQuery(name = \"Place.getPla
If you are using positional parameters, you can use this way
@Query("select p from ABC p where p.name like CONCAT('%',?1,'%') ")
You can't have the % in the NamedQuery
, but you can have it in the value you assign the parameter.
As in:
String city = "needle";
query.setParamter("city", "%" + city + "%");
You can also use CONCAT function
@NamedQuery(name = "Place.getPlaceForCityAndCountryName",
query = "SELECT p FROM Place p WHERE " +
"lower(p.city) like CONCAT(:city,'%')");
@Query("select c from Curso c where c.descripcion like CONCAT(:descripcion,'%')")
List<Curso> findByDescripcionIgnoreCase(@Param("descripcion") String descripcion);