From 79911fbf18d1bade18672ada9423ec1d6ba2159a Mon Sep 17 00:00:00 2001 From: AurMario <149056878+AurMario@users.noreply.github.com> Date: Thu, 26 Oct 2023 11:17:36 +0200 Subject: [PATCH] Use HQL parser when Hibernate 5 is on the classpath. Closes #3212 --- .../data/jpa/repository/query/QueryEnhancerFactory.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryEnhancerFactory.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryEnhancerFactory.java index 74aa77e611..a78ef74693 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryEnhancerFactory.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/repository/query/QueryEnhancerFactory.java @@ -25,6 +25,7 @@ * @author Diego Krupitza * @author Greg Turnquist * @author Mark Paluch + * @author Aurelien Marionneau * @since 2.7.0 */ public final class QueryEnhancerFactory { @@ -37,13 +38,16 @@ public final class QueryEnhancerFactory { private static final boolean hibernatePresent = ClassUtils.isPresent("org.hibernate.query.TypedParameterValue", QueryEnhancerFactory.class.getClassLoader()); + private static final boolean hibernate5Present = ClassUtils.isPresent("org.hibernate.jpa.TypedParameterValue", + QueryEnhancerFactory.class.getClassLoader()); + static { if (jSqlParserPresent) { LOG.info("JSqlParser is in classpath; If applicable, JSqlParser will be used"); } - if (hibernatePresent) { + if (hibernatePresent || hibernate5Present) { LOG.info("Hibernate is in classpath; If applicable, HQL parser will be used."); } } @@ -70,7 +74,7 @@ public static QueryEnhancer forQuery(DeclaredQuery query) { return new DefaultQueryEnhancer(query); } - return hibernatePresent ? JpaQueryEnhancer.forHql(query) : JpaQueryEnhancer.forJpql(query); + return (hibernatePresent || hibernate5Present) ? JpaQueryEnhancer.forHql(query) : JpaQueryEnhancer.forJpql(query); } }