I have a query where I need to check first if the input parameter is null or compare the column value to pass input parameter. It means that the column value can be null or pass the specified condition (?3 is null or cd.name like %?3%).
public interface PageableCategoryRepository extends PagingAndSortingRepository<Category, Long> {
@Query(
value = "select distinct c from Category c left join fetch c.descriptions cd join fetch cd.language cdl join fetch c.merchantStore cm"
+ " where cm.id=?1 and cdl.id=?2 and (?3 is null or cd.name like %?3%) order by c.lineage, c.sortOrder asc",
countQuery = "select count(c) from Category c join c.descriptions cd join c.merchantStore cm "
+ "where cm.id=?1 and cd.language.id=?2 and (?3 is null or cd.name like %?3%)")
Page<Category> listByStore(Integer storeId, Integer languageId, String name, Pageable pageable);
}
The above query is failing for the null value passed in name property. Error:
ERROR: operator does not exist: character varying ~~ bytea Hint: No operator matches the given name and argument types. You might need to add explicit type casts. Position: 3259
I tried to search on google as well as here on Stack Overflow. There are many similar questions asked & answered. But none of those solutions work for me.
Would really appreciate if anybody can provide some insight or direction.
Note: Spring boot version- 2.2.7.RELEASE, Postgresql library version used- 42.2.16, Postgresql version used- 12.4