spring-data-jpa icon indicating copy to clipboard operation
spring-data-jpa copied to clipboard

Allow configuration of transformation for case-insensitive queries

Open ViktarRVR opened this issue 3 years ago • 13 comments

We use Spring Data JPA + Querydsl JPA. If we perform queries with ignoreCase keyword in repository methods Spring data JPA use UPPER function on parameters in SQL(as described in documentation, Table 3. Supported keywords inside method names), but Querydsl JPA uses LOWER function. We should use two types of indexes or don't use ignoreCase keyword in repository methods.

It would be great, if it was possible to configured to use UPPER function or LOWER function in Spring Data JPA.

See also #3540

ViktarRVR avatar Jan 26 '22 09:01 ViktarRVR

FTR: https://github.com/querydsl/querydsl/blob/99e3ca936f46471bc61d9af6e1a3dbb16f3f12b3/querydsl-jpa/src/main/java/com/querydsl/jpa/JPQLTemplates.java

mp911de avatar Feb 07 '22 15:02 mp911de

I ran into the same problem in the query by example code. It also appears to be hard-coded to use a lower conversion. As stated above, this is challenging because I only want to maintain a single case-insensitive index on either the upper or lowercase version of certain columns.

See https://github.com/spring-projects/spring-data-jpa/blob/main/src/main/java/org/springframework/data/jpa/convert/QueryByExamplePredicateBuilder.java#L182.

It would be great if this were able to be customized in the ExampleMatcher methods.

steveratay avatar Mar 04 '22 15:03 steveratay

Whereas another knob would work, I wonder if it isn't simpler to just update things to use lower across the board.

gregturn avatar Mar 18 '22 18:03 gregturn

Going consistently with lower sounds like a good way to go. Please make sure to have this change included in release notes since it might disable existing indexes and therefore cause a performance degradation when not addressed.

schauder avatar Mar 22 '22 09:03 schauder

This has been merged to main and to 3.0.x.

gregturn avatar Mar 22 '22 19:03 gregturn

Release notes https://github.com/spring-projects/spring-data-commons/wiki/Release-Train-2021.2-(Raj)-Release-Notes-(Preview) have been updated.

gregturn avatar Mar 22 '22 19:03 gregturn

Did this get reverted, or did I miss something? According to the logged HQL, 3.2.2 is using upper instead of lower.

Edit: 15e8e3bfe8396e7e151e7e540ed0b040593f1cfa doesn't look right at all. All it did was change a variable name from lower to upper.

OrangeDog avatar Feb 15 '24 15:02 OrangeDog

I am with @OrangeDog - I just wrapped up dropping an UPPER index thinking this had been resolved in 2.7.x, only to discover that a ~~QueryDsl~~ Repository IgnoreCase method is still generating where upper(...)=upper(?)

I am on 2.7.18 for this project, upgraded to 2.6.x, and was following the release notes assuming this had been fixed in 2.7: https://github.com/spring-projects/spring-data-commons/wiki/Spring-Data-2021.2-(Raj)-Release-Notes#ignorecase-operators-now-use-lower-functions-across-the-board

danwatt avatar Feb 15 '24 18:02 danwatt

@danwatt QueryDSL is using lower, repositories are using upper. Same as described in the original issue.

OrangeDog avatar Feb 15 '24 19:02 OrangeDog

@gregturn @mp911de can this be reopened? It was not fixed. It looks like someone messed up resolving conflicts in the merge or something.

OrangeDog avatar Nov 19 '24 11:11 OrangeDog

Sure. We've started exploring configuration for ignore-case transformations with https://github.com/spring-projects/spring-data-jpa/pull/3653/files#diff-fdc19ed3d18aab513d05cd0418ab02dbaa8f1bdf5f8f8574d26d1ecdd9914486

mp911de avatar Nov 19 '24 12:11 mp911de

This change concerns:

  • Derived Queries (JPQL)
  • Querydsl
  • QueryByExamplePredicateBuilder
  • SimpleJpaRepository

for Sorting and predicates

mp911de avatar Nov 22 '24 09:11 mp911de

Is there any plan to actually fix this issue as originally intended (i.e. make everything use lower)? That would be much easier than adding new configuration.

OrangeDog avatar Nov 22 '24 10:11 OrangeDog