Skip to content

Commit 2219952

Browse files
committed
Fetch HQL from Hibernate using a different API.
See #3085
1 parent b11fae8 commit 2219952

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

spring-data-jpa/src/main/java/org/springframework/data/jpa/provider/HibernateUtils.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,23 @@ public static String getHibernateQuery(Object query) {
4545
try {
4646

4747
// Try the new Hibernate implementation first
48-
if (query instanceof SqmQuery) {
49-
return ((SqmQuery) query).getSqmStatement().toHqlString();
48+
if (query instanceof SqmQuery sqmQuery) {
49+
50+
String hql = sqmQuery.getQueryString();
51+
52+
if (!hql.equals("<criteria>")) {
53+
return hql;
54+
}
55+
56+
return sqmQuery.getSqmStatement().toHqlString();
5057
}
5158

5259
// Couple of cases in which this still breaks, see HHH-15389
5360
} catch (RuntimeException o_O) {}
5461

5562
// Try the old way, as it still works in some cases (haven't investigated in which exactly)
56-
57-
if (query instanceof Query) {
58-
return ((Query<?>) query).getQueryString();
63+
if (query instanceof Query<?> hibernateQuery) {
64+
return hibernateQuery.getQueryString();
5965
} else {
6066
throw new IllegalArgumentException("Don't know how to extract the query string from " + query);
6167
}

0 commit comments

Comments
 (0)