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..3cd9b642d2 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,7 +48,16 @@ public static String getHibernateQuery(Object query) { // Try the new Hibernate implementation first if (query instanceof SqmQuery sqmQuery) { - return sqmQuery.getSqmStatement().toHqlString(); + + String hql = sqmQuery.getQueryString(); + + if (!hql.equals("")) { + return hql; + } + + String sqmHql = sqmQuery.getSqmStatement().toHqlString(); + + return sqmHql; } // Couple of cases in which this still breaks, see HHH-15389