|
16 | 16 | import static java.util.stream.Collectors.toList;
|
17 | 17 | import static org.omnifaces.persistence.Database.POSTGRESQL;
|
18 | 18 | import static org.omnifaces.persistence.Provider.HIBERNATE;
|
19 |
| -import static org.omnifaces.utils.reflect.Reflections.findClass; |
| 19 | +import static org.omnifaces.utils.reflect.Reflections.findMethod; |
20 | 20 | import static org.omnifaces.utils.reflect.Reflections.invokeMethod;
|
21 | 21 | import static org.omnifaces.utils.stream.Collectors.toMap;
|
22 | 22 | import static org.omnifaces.utils.stream.Streams.stream;
|
@@ -79,10 +79,6 @@ public final class JPA {
|
79 | 79 | public static final String QUERY_HINT_CACHE_RETRIEVE_MODE = "jakarta.persistence.cache.retrieveMode"; // USE | BYPASS
|
80 | 80 | public static final String PROPERTY_VALIDATION_MODE = "jakarta.persistence.validation.mode"; // AUTO | CALLBACK | NONE
|
81 | 81 |
|
82 |
| - // Private constants ------------------------------------------------------------------------------------------------------------------ |
83 |
| - |
84 |
| - private static final Optional<Class<Object>> HIBERNATE_6_6_0_JPA_EXPRESSION = findClass("org.hibernate.query.criteria.JpaExpression"); |
85 |
| - |
86 | 82 | // Constructors -----------------------------------------------------------------------------------------------------------------------
|
87 | 83 |
|
88 | 84 | private JPA() {
|
@@ -362,8 +358,10 @@ public static Expression<String> castAsString(CriteriaBuilder builder, Expressio
|
362 | 358 | // NOTE: Improvement for all providers is expected in JPA 3.2 with new Expression#cast() API.
|
363 | 359 |
|
364 | 360 | if (Provider.is(HIBERNATE)) {
|
365 |
| - if (HIBERNATE_6_6_0_JPA_EXPRESSION.isPresent() && HIBERNATE_6_6_0_JPA_EXPRESSION.get().isInstance(expression)) { |
366 |
| - return invokeMethod(expression, "cast", String.class); // https://hibernate.atlassian.net/browse/HHH-18710 |
| 361 | + var cast = findMethod(expression, "cast", Class.class); |
| 362 | + |
| 363 | + if (cast.isPresent()) { // Hibernate 6.6.0. |
| 364 | + return invokeMethod(expression, cast.get(), String.class); // https://hibernate.atlassian.net/browse/HHH-18710 |
367 | 365 | }
|
368 | 366 | else {
|
369 | 367 | return expression.as(String.class);
|
|
0 commit comments