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
Using Java 8 named parameter prevents positional query parameter binding [DATAJPA-758] #1129
Comments
Oliver Drotbohm commented Good catch! I've just pushed a patch that basically skips the parameter validation if we find the query is not using named parameters at all. Feel free to give the snapshots a spin |
Michael Wiles commented Yes, this particular issue has been addressed... However the following scenario still persists... This might need another JIRA: @Query("select r from Role r where ?1 member of r.permissions")
public List<Role> findByPermission(Permission permission); Works when parameter names are enabled and on 1.8.2.BUILD-SNAPSHOT (This did not work before). But what doesn't work is the following: public Tenant findByKey(String key); It is rejected with exception:
The same can be replicated by adding So ```java
|
Oliver Drotbohm commented I gave it another spin and tweaked the default behavior slightly. We're now able to detect whether a parameter has been explicitly named (i.e. annotated) and only then use the by-name binding. This is to make sure that if a user uses |
Michael Wiles commented Thanks. Tested and Works. Error on ```java
|
Oliver Drotbohm commented Awesome, thanks! |
Michael Wiles opened DATAJPA-758 and commented
When I turned on parameter naming in the java 8 compiler all the non named parameters I have no longer work.
In other words, Spring Data JPA insists on using the parameter name...
Simple Example:
Works fine without parameter names added to compiler.
When I turn on the inclusion of parameter names I get this error:
And if I now change it to:
It works again...
This could be by design - I understand that if it is the case. i.e. when you turn on parameter name inclusion then you must name all your parameters.
A fall back to "non named" would be ideal if scanning with parameter names is not successful but that might be too much overhead.
Though another option would be to allow the user to turn off using named parameters even when available. Developers might require parameter names in classes for some unrelated purpose and turning it on would break all their JPA queries (as they have not used it up to now).
Maybe making it configurable per repository is an alternative...
Affects: 1.8.1 (Fowler SR1)
Issue Links:
Referenced from: commits 8de3100, e8e8e1b, 7796165, 0cbfefc
Backported to: 1.8.2 (Fowler SR2)
The text was updated successfully, but these errors were encountered: