Decapitalization of property names in repository queries breaks for properties with single lowercase letter followed by an uppercase letter [DATACMNS-1589] #2016
Labels
in: repository
Repositories abstraction
status: declined
A suggestion or change that we don't feel we should currently apply
Andre Kupka opened DATACMNS-1589 and commented
The property resolution in custom repository queries fails if the property name starts with a single lowercase letter followed by an uppercase letter. The following entity and repository demonstrate the problem:
Entity
Repository
In Spring Boot version 2.1.8.RELEASE (includes spring-data-commons 2.1.10.RELEASE) the code above was working but in version 2.1.9.RELEASE (includes spring-data-commons 2.1.11.RELEASE) the following exception was thrown:
I have implemented a minimal working example in https://github.com/andrekupka/jpa-property-name-resolution to reproduce the behavior and tagged a working, a broken and two workaround versions:
Working version: https://github.com/andrekupka/jpa-property-name-resolution/tree/working/2.1.8
Broken version: https://github.com/andrekupka/jpa-property-name-resolution/tree/not-working/2.1.9
Workaround with a custom Query annotation: https://github.com/andrekupka/jpa-property-name-resolution/tree/fix/query
Workaround by renaming the query method: https://github.com/andrekupka/jpa-property-name-resolution/tree/fix/property-renaming
The Testcase
CustomerRepositoryTest
can be used to reproduce the behavior.The regression was introduced with PR #402 which uses https://docs.oracle.com/javase/7/docs/api/java/beans/Introspector.html#decapitalize(java.lang.String) for property decapitalization instead of Spring's own StringUtils class.
Tthe documentation at https://docs.spring.io/spring-data/data-commons/docs/current/reference/html/#repositories.query-methods.query-property-expressions does not mention the changed behavior as well. The documentation states that the first character of the property is decapitalized therefore the former example should still work.
Solution Proposal
I think using the decapitalization from the Java Bean Introspector is the correct behavior, thus the documentation should be updated and explicitly mention this special case.
Affects: 2.1.11 (Lovelace SR11)
Issue Links:
The text was updated successfully, but these errors were encountered: