From c040cfaeb1dd920497fd034db7f728a15c664521 Mon Sep 17 00:00:00 2001 From: "Greg L. Turnquist" Date: Mon, 24 Jul 2023 14:08:31 -0500 Subject: [PATCH] Fetch HQL from Hibernate using a different API. See #3085 --- .../springframework/data/jpa/provider/HibernateUtils.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java b/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java index ccecfb52a4..c5b3ce423e 100644 --- a/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java +++ b/spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java @@ -48,6 +48,13 @@ public static String getHibernateQuery(Object query) { // Try the new Hibernate implementation first if (query instanceof SqmQuery sqmQuery) { + + String hql = sqmQuery.getQueryString(); + + if (!hql.equals("")) { + return hql; + } + return sqmQuery.getSqmStatement().toHqlString(); } @@ -55,7 +62,6 @@ public static String getHibernateQuery(Object query) { } catch (RuntimeException o_O) {} // Try the old way, as it still works in some cases (haven't investigated in which exactly) - if (query instanceof Query hibernateQuery) { return hibernateQuery.getQueryString(); } else {