According to this Link
Predicate lcSurnameLikeSearchPattern = criteriaBuilder.like( criteriaBuilder.lower(Person_.surname), searchPattern.toLowerCase());
This seems like Hibernate would generate an SQL that would look something like
LOWER(PERSON.SURNAME) LIKE 'searchPattern'
Where searchPattern would have been lowered in Java using whatever implementation toLowerCase would provide. Whereas the query LOWER would use Oracle implementation. For ASCII characters, I'm guessing things are pretty simple, but would there ever be discrepancies on international UTF characters?
How would I get JPA to lower both operands of LIKE in the query? So the generated query looks like
LOWER(PERSON.SURNAME) LIKE LOWER('searchPattern')
You can use two Expressions as like
method parameters and literal
to wrap a String into Expression:
Predicate lcSurnameLikeSearchPattern = criteriaBuilder.like(
criteriaBuilder.lower(Person_.surname),
criteriaBuilder.lower(criteriaBuilder.literal(searchPattern))
);
CriteriaBuilder#like(Expression,Expression)
CriteriaBuilder#lower(Expression)
CriteriaBuilder#literal(T)
I ommit Person_.surname
definition as it is from your example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With