(Hibernate3+)HQL转SQL


import java.util.Collections;

import org.hibernate.SessionFactory;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.hql.internal.ast.QueryTranslatorImpl;

public class HQLUtils{
	
	public String hqlToSql(SessionFactory sessionFactory,String hql){
		QueryTranslatorImpl queryTranslator=new QueryTranslatorImpl(hql,hql,Collections.EMPTY_MAP,(SessionFactoryImplementor)sessionFactory);
		queryTranslator.compile(Collections.EMPTY_MAP, false);
		return queryTranslator.getSQLString();
	}
}


你可能感兴趣的:(HQL,Hibernate4,hibernate3)