Skip to content

Commit

Permalink
Fetch HQL from Hibernate using a different API.
Browse files Browse the repository at this point in the history
See #3085
  • Loading branch information
gregturn committed Sep 12, 2023
1 parent b11fae8 commit 2219952
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,23 @@ public static String getHibernateQuery(Object query) {
try {

// Try the new Hibernate implementation first
if (query instanceof SqmQuery) {
return ((SqmQuery) query).getSqmStatement().toHqlString();
if (query instanceof SqmQuery sqmQuery) {

String hql = sqmQuery.getQueryString();

if (!hql.equals("<criteria>")) {
return hql;
}

return sqmQuery.getSqmStatement().toHqlString();
}

// Couple of cases in which this still breaks, see HHH-15389
} 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) {
return ((Query<?>) query).getQueryString();
if (query instanceof Query<?> hibernateQuery) {
return hibernateQuery.getQueryString();
} else {
throw new IllegalArgumentException("Don't know how to extract the query string from " + query);
}
Expand Down

0 comments on commit 2219952

Please sign in to comment.