I'd like to get the sql string from a CriteriaQuery using Hibernate 6.
CriteriaQuery
.SQLExtractor.from()
dos not work either because it just uses reflection to call Query.getQueryString()Any ideas?
UPDATE: This solution is for HQL, I misread the question. For SQL, see @PawelP's answer.
This was an intentional design decision by the Hibernate team in version 6 as Hibernate moved to the semantic query model. I did find a workaround to do this in the following code. It's worth noting that the format of the HQL this method returns has changed slightly since Hibernate 5:
QuerySqmImpl<?> unwrap = entityManager.createQuery(query).unwrap(QuerySqmImpl.class);
String queryString = unwrap.getSqmStatement().toHqlString();
You can see some discussion around this in the Hibernate JIRA ticket for this issue as well.