Skip to content

Implicit count query (paging) fails when using like/in clause combined with parameter null check #3799

Closed as duplicate of#3784
@Cloud5000

Description

@Cloud5000

Starting with 3.3.9 the following query fails:

@Query("select t from TestTable t where :testColumnValue is null or t.testColumn like %:testColumnValue%") Page<TestTable> test(@Param("testColumnValue") String testColumnValue, Pageable pageable);

Caused by: org.hibernate.QueryParameterException: No argument for named parameter ':testColumnValue_1' at org.hibernate.query.internal.QueryParameterBindingsImpl.lambda$validate$0(QueryParameterBindingsImpl.java:142) at java.base/java.util.ArrayList.forEach(ArrayList.java:1596) at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116) at org.hibernate.query.internal.ParameterMetadataImpl.visitParameters(ParameterMetadataImpl.java:191) at org.hibernate.query.spi.ParameterMetadataImplementor.visitRegistrations(ParameterMetadataImplementor.java:29) at org.hibernate.query.internal.QueryParameterBindingsImpl.validate(QueryParameterBindingsImpl.java:138) at org.hibernate.query.spi.AbstractSelectionQuery.beforeQuery(AbstractSelectionQuery.java:446) at org.hibernate.query.spi.AbstractSelectionQuery.beforeQueryHandlingFetchProfiles(AbstractSelectionQuery.java:439) at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:420) at org.hibernate.query.Query.getResultList(Query.java:120) at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103) at java.base/java.lang.reflect.Method.invoke(Method.java:580) at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:418) at jdk.proxy2/jdk.proxy2.$Proxy297.getResultList(Unknown Source) at org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.count(JpaQueryExecution.java:211)

So it is not the SELECT query itself that fails but the implicit COUNT query afterwards when there are more items then requested (> page size).

Apparently it doesn't recognize that the parameter for the null check and the like clause are the same. A new parameter with '_1' suffix is introduced whose value could not be found.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions