Created
May 3, 2024 03:00
-
-
Save prameshbajra/c57eb60d488d43490dc710c769643bd8 to your computer and use it in GitHub Desktop.
CriteriaQuery to SQL print.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.hibernate.Session session = entityManager.unwrap(org.hibernate.Session.class); | |
org.hibernate.query.Query<?> query = session.createQuery(criteriaQuery); | |
SharedSessionContractImplementor sessionImplementor = entityManager.unwrap(SharedSessionContractImplementor.class); | |
String sql = sessionImplementor.getFactory() | |
.getQueryPlanCache() | |
.getHQLQueryPlan(query.getQueryString(), false, Collections.emptyMap()) | |
.getSqlStrings()[0]; | |
System.out.println("Generated SQL: " + sql); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment