Skip to content

Instantly share code, notes, and snippets.

@Chuckame
Created August 6, 2021 13:43
Show Gist options
  • Save Chuckame/5638fc1109c601acb6eaa9c2640f7c59 to your computer and use it in GitHub Desktop.
Save Chuckame/5638fc1109c601acb6eaa9c2640f7c59 to your computer and use it in GitHub Desktop.
Converts an HQL to SQL
String toSQL(EntityManager em, String hql) {
SessionImplementor hibernateSession = em.unwrap(SessionImplementor.class);
HQLQueryPlan p = new HQLQueryPlan(hql, false, Map.of(), hibernateSession.getSessionFactory());
if (p.getTranslators().length > 1) {
throw new UnsupportedOperationException();
}
return p.getTranslators()[0].getSQLString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment