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 {