Hibernate版本3.3.2GA
protected String hqlToSql(String hql,
org.hibernate.SessionFactory sessionFactory) throws Exception {
org.hibernate.hql.ast.QueryTranslatorImpl queryTranslator = new org.hibernate.hql.ast.QueryTranslatorImpl(
hql, hql, java.util.Collections.EMPTY_MAP,
(org.hibernate.engine.SessionFactoryImplementor) sessionFactory);
queryTranslator.compile(java.util.Collections.EMPTY_MAP, false);
return queryTranslator.getSQLString();
}
注:
以上转出来的SQL是不带参数值的,即HQL中的?转换后仍然是?。
转成完全可直接copy执行的SQL,尚在研究中……