How to convert HQL to SQL Query programmatically (without logging)

后端 未结 7 1165
刺人心
刺人心 2021-02-05 12:10

I am executing the following HQL and it is executing properly

String hql = \"FROM Employee\";
Query query = session.createQuery(hql);
List results = query.list(         


        
7条回答
  •  长发绾君心
    2021-02-05 12:49

    I found next solution on the web:

    QueryTranslatorFactory translatorFactory = new ASTQueryTranslatorFactory();
    SessionFactoryImplementor factory = (SessionFactoryImplementor) getSessionFactory();
    QueryTranslator translator = translatorFactory.
            createQueryTranslator(hqlQueryText, hqlQueryText, Collections.EMPTY_MAP, factory);
    translator.compile(Collections.EMPTY_MAP, false);
    translator.getSQLString(); 
    

    Source: http://narcanti.keyboardsamurais.de/hibernate-hql-to-sql-translation.html

提交回复
热议问题