Skip to content

Convert @Query method Iterable parameters like findBy* query methods #1226

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
wants to merge 2 commits into from

Conversation

ctailor2
Copy link
Contributor

There is currently limited support for @Query methods with Iterable parameters, which may be used, for example, in declaring a query with the SQL IN operator. For such parameters, the interpretation of the query and the supplied arguments works as expected as long as the Iterable parameter generic type can be handled directly by the JDBC driver without conversion. If conversion is required, for example when using Iterable<Enum>, the method invocation fails as the driver cannot handle Enum types natively.

These changes carry over the logic for conversion of Iterable values from QueryMapper#convertToJdbcValue, which is used to resolve parameters for findBy* methods, into StringBasedJdbcQuery to provide more complete support for such parameters in @Query methods.

Closes #1212

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Apr 19, 2022
+ Copy logic from QueryMapper#convertToJdbcValue to resolve Iterable
  arguments on findBy* query methods to resolve the same for @query.
+ Use parameter ResolvableType instead of Class to retain generics info.
@ctailor2 ctailor2 force-pushed the issue/1212-query-in-clause-with-enum branch from ffadf48 to 8412774 Compare April 19, 2022 19:53
@ctailor2 ctailor2 requested a review from schauder April 19, 2022 19:53
schauder pushed a commit that referenced this pull request May 17, 2022
+ Copy logic from QueryMapper#convertToJdbcValue to resolve Iterable
  arguments on findBy* query methods to resolve the same for @query.
+ Use parameter ResolvableType instead of Class to retain generics info.

Original pull request #1226
Closes #1212
schauder added a commit that referenced this pull request May 17, 2022
Original pull request #1226
See #1212
schauder pushed a commit that referenced this pull request May 17, 2022
+ Copy logic from QueryMapper#convertToJdbcValue to resolve Iterable
  arguments on findBy* query methods to resolve the same for @query.
+ Use parameter ResolvableType instead of Class to retain generics info.

Original pull request #1226
Closes #1212
schauder added a commit that referenced this pull request May 17, 2022
Original pull request #1226
See #1212
schauder pushed a commit that referenced this pull request May 17, 2022
+ Copy logic from QueryMapper#convertToJdbcValue to resolve Iterable
  arguments on findBy* query methods to resolve the same for @query.
+ Use parameter ResolvableType instead of Class to retain generics info.

Original pull request #1226
Closes #1212
schauder added a commit that referenced this pull request May 17, 2022
Original pull request #1226
See #1212
@schauder
Copy link
Contributor

Thanks, that's merged and backported.

@schauder schauder closed this May 17, 2022
@schauder schauder deleted the issue/1212-query-in-clause-with-enum branch May 17, 2022 14:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enum type in Query annotation does not work in in clause
3 participants