java
@RestResource(exported = false)
@Query("""
SELECT DISTINCT fq FROM FilterQuery fq
WHERE (
( :filterName is NULL OR fq.filterName LIKE CONCAT('%', :filterName, '%'))
AND (:ownerId IS NULL OR fq.owner.id = :ownerId)
""")
Page<FilterQueryListProjection> findAllWithViewPermission(@Param("userId") Long userId,
@Param("groupIds") List<Long> groupIds,
@Param("filterName") String filterName,
@Param("ownerId") Long ownerId,
Pageable pageable);
hql 会报错
java
Caused by: org.hibernate.exception.SQLGrammarException: JDBC exception executing SQL [select distinct fq1_0.id,fq1_0.created_by,fq1_0.created_time,fq1_0.description,fq1_0.entity_name,fq1_0.filter,fq1_0.filter_name,fq1_0.hql_condition,fq1_0.is_default,fq1_0.owner_id,fq1_0.spel_condition,fq1_0.sql_condition,fq1_0.updated_by,fq1_0.updated_time from filter_query fq1_0 where (fq1_0.owner_id=? or not exists(select 1 from filter_query_permission_set fqps1_0 where fqps1_0.filter_query_id=fq1_0.id and fqps1_0.permission_type='VIEW') or exists(select 1 from filter_query_permission fqp1_0 join filter_query_permission_set ps1_0 on ps1_0.id=fqp1_0.permission_set_id where ps1_0.filter_query_id=fq1_0.id and ps1_0.permission_type='VIEW' and fqp1_0.user_id=?) or exists(select 1 from filter_query_permission fqp2_0 join filter_query_permission_set ps2_0 on ps2_0.id=fqp2_0.permission_set_id where ps2_0.filter_query_id=fq1_0.id and ps2_0.permission_type='VIEW' and fqp2_0.group_id in (?,?,?))) and (? is null or fq1_0.filter_name like ('%'||?||'%') escape '') and (? is null or fq1_0.owner_id=?) order by fq1_0.created_time desc fetch first ? rows only] [ERROR: operator does not exist: character varying ~~ bytea
关键: [ERROR: operator does not exist: character varying ~~ bytea
改成
AND ( COALESCE(:filterName, '') = '' OR fq.filterName LIKE CONCAT('%', :filterName, '%'))
就ok