Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No argument for named parameter using parameter multiple times with IN binding #3784

Closed
AlexanderShchelkunov opened this issue Feb 21, 2025 · 8 comments
Assignees
Labels
type: regression A regression from a previous release

Comments

@AlexanderShchelkunov
Copy link

AlexanderShchelkunov commented Feb 21, 2025

Description

Hello!

I have encountered the problem in version 3.3.9 (works fine in 3.3.8).
When I have a query with a parameter, that used multiple time in query with paging, I have the following error:
org.springframework.dao.InvalidDataAccessResourceUsageException: No argument for named parameter ':logins_1'
It is important to have more data in the database, than page size, to trigger additional count query.
Example of the query:

@Query(
  value = """
      SELECT d
      FROM UserEntity d
      WHERE (:logins) IS NULL OR LOWER(d.login) IN (:logins)
      """
)
Page<UserEntity> findByLogins(@Param("logins") Set<String> logins, Pageable pageable);

Environment

Spring Boot: 3.3.9
Java: JDK 17

Steps to Reproduce

To reproduce the defect run the app and the error will occur during @PostConstruct execution in UserService

Error Message

Caused by: org.hibernate.QueryParameterException: No argument for named parameter ':logins_1'
	at org.hibernate.query.internal.QueryParameterBindingsImpl.lambda$validate$0(QueryParameterBindingsImpl.java:142) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511) ~[na:na]
	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1092) ~[na:na]
	at org.hibernate.query.internal.ParameterMetadataImpl.visitParameters(ParameterMetadataImpl.java:191) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at org.hibernate.query.spi.ParameterMetadataImplementor.visitRegistrations(ParameterMetadataImplementor.java:29) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at org.hibernate.query.internal.QueryParameterBindingsImpl.validate(QueryParameterBindingsImpl.java:138) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at org.hibernate.query.spi.AbstractSelectionQuery.beforeQuery(AbstractSelectionQuery.java:446) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at org.hibernate.query.spi.AbstractSelectionQuery.beforeQueryHandlingFetchProfiles(AbstractSelectionQuery.java:439) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at org.hibernate.query.spi.AbstractSelectionQuery.list(AbstractSelectionQuery.java:420) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at org.hibernate.query.Query.getResultList(Query.java:120) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.count(JpaQueryExecution.java:211) ~[spring-data-jpa-3.3.9.jar:3.3.9]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.lambda$0(JpaQueryExecution.java:206) ~[spring-data-jpa-3.3.9.jar:3.3.9]
	at org.springframework.data.support.PageableExecutionUtils.getPage(PageableExecutionUtils.java:63) ~[spring-data-commons-3.3.9.jar:3.3.9]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.doExecute(JpaQueryExecution.java:205) ~[spring-data-jpa-3.3.9.jar:3.3.9]
	at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:93) ~[spring-data-jpa-3.3.9.jar:3.3.9]
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:152) ~[spring-data-jpa-3.3.9.jar:3.3.9]
	at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:140) ~[spring-data-jpa-3.3.9.jar:3.3.9]
...

Minimal sample application

See the attachment:
QueryParameterException_demo.zip

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 21, 2025
@x41dev
Copy link

x41dev commented Feb 21, 2025

Hello,

I had similar case and I've found workaround: When I used :#{#logins} instead of :logins problem disappear.
Maybe it will help somehow

@AlexanderShchelkunov
Copy link
Author

Hello,

I had similar case and I've found workaround: When I used :#{#logins} instead of :logins problem disappear. Maybe it will help somehow

Hi @x41dev!
Thanks for sharing the workaround. It's very helpful!

@mp911de mp911de self-assigned this Feb 24, 2025
@mp911de mp911de added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 24, 2025
@hkucharek-pgt
Copy link

We had the same problem with 3.4.3 and after downgrading to 3.4.2 it worked again.

@mp911de mp911de changed the title [3.3.9] Error binding parameter that is used multiple times in query with paging (doCreateCountQuery) No argument for named parameter using parameter multiple times with IN binding Feb 24, 2025
@mp911de mp911de added type: regression A regression from a previous release and removed type: bug A general bug labels Feb 24, 2025
@mp911de mp911de added this to the 3.3.11 (2024.0.11) milestone Feb 24, 2025
mp911de added a commit that referenced this issue Feb 24, 2025
We've now expanded parameter post-processing for derived count queries to consider binding types (in, like) and to correctly retain invocation parameter redirects instead of assuming an exact mapping of parameter positions in the final query to the actual invocation argument names/indices.

Closes #3784
mp911de added a commit that referenced this issue Feb 24, 2025
We've now expanded parameter post-processing for derived count queries to consider binding types (in, like) and to correctly retain invocation parameter redirects instead of assuming an exact mapping of parameter positions in the final query to the actual invocation argument names/indices.

Closes #3784
@mp911de
Copy link
Member

mp911de commented Feb 24, 2025

Regression was introduced through 88b6ea2. New snapshots are on their way into repo.spring.io. Care to upgrade to and test against 3.3.10-SNAPSHOT?

@AlexanderShchelkunov
Copy link
Author

Regression was introduced through 88b6ea2. New snapshots are on their way into repo.spring.io. Care to upgrade to and test against 3.3.10-SNAPSHOT?

Hi @mp911de!
Thanks for the fix! It works fine in 3.3.10-SNAPSHOT.

@mp911de
Copy link
Member

mp911de commented Feb 25, 2025

Thanks for verifying.

@mcs
Copy link

mcs commented Feb 26, 2025

Will this patch also be part of the upcoming 3.4.4 release, as 3.4.3 also has that problem as mentioned in #3789 ?

@mp911de mp911de marked this as a duplicate of #3789 Feb 26, 2025
@mp911de
Copy link
Member

mp911de commented Feb 26, 2025

Yes, the fix will be shipped with 3.4.4, 3.3.10. and 3.5.0-M2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

6 participants