Skip to content

ParameterBinding does not work when the same parameter (whose type is a List) is used multiple times #3131

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

Closed
falcononrails opened this issue Aug 29, 2023 · 2 comments
Labels
status: duplicate A duplicate of another issue

Comments

@falcononrails
Copy link

falcononrails commented Aug 29, 2023

Hello,

I am upgrading from Spring Boot 3.0.9 to 3.1.3 and I'm having the same issue on this query (which was working perfectly before):

@Query(value = """
         /* select and joins */
         where
                and (:encryptedEmail = '' or :encryptedEmail is null or c.encrypted_email = :encryptedEmail) \
                and (:name = '' or :name is null or cp.name like %:name%) \
                and (org.id in :ids or coalesce(:ids) is null)
        """, nativeQuery = true)
    List<View> findAll(String encryptedEmail, String name, List<Integer> ids);
Caused by: java.lang.IllegalArgumentException: Already found parameter binding with same index / parameter name but differing binding type; Already have: ParameterBinding [identifier: ids, origin: MethodInvocationArgument[identifier=ids]], found ParameterBinding [identifier: ids, origin: MethodInvocationArgument[identifier=ids]]; If you bind a parameter multiple times make sure they use the same binding
	at org.springframework.util.Assert.isTrue(Assert.java:122)

What's surprising is that I'm using encryptedEmail and name twice in both clauses, yet the error arises only for the third clause containing ids. Has this been fixed only for certain cases?

I also tried without using coalesce: :ids is null or org.id in :ids and I'm getting the same error. I also tried inverting the where clauses, putting the last one in a different position, and I have the same error only on the statement containing :ids.
I also tried going old school and using ?1, ?2, and ?3 instead of the variable names, but I also get the same error with identifier: 3 this time.

I think the difference is that the last parameter is a list and that confuses the validator.

Originally posted by @falcononrails in #1230 (comment)

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 29, 2023
@mp911de
Copy link
Member

mp911de commented Aug 29, 2023

Looks like a duplicate of #3126. Care to upgrade to the latest Spring Data JPA snapshot (3.1.4-SNAPSHOT) and retest, whether the fix addresses your issue?

@mp911de mp911de added status: duplicate A duplicate of another issue status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 29, 2023
@falcononrails
Copy link
Author

It works as expected with 3.1.4-SNAPSHOT, thank you for the quick reply!

@mp911de mp911de removed the status: waiting-for-feedback We need additional information before we can continue label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

3 participants