I do it, if that can help :
Code:
Ejb3Configuration cfg = new Ejb3Configuration();
Ejb3Configuration configured = cfg.configure("myPersistenceUnit",
new HashMap());
EntityManagerFactory emf = configured.buildEntityManagerFactory();
EntityManager em = emf.createEntityManager();
Map enabledFilters = ((SessionImpl) em.getDelegate()).getEnabledFilters();
QueryPlanCache queryPlanCache = ((SessionFactoryImpl) ((EntityManagerFactoryImpl) emf)
.getSessionFactory()).getQueryPlanCache();
Map queries = configured.getNamedQueries();
for (Iterator iter = queries.values().iterator(); iter.hasNext();) {
NamedQueryDefinition pNamedQueryDefinition = (NamedQueryDefinition) iter
.next();
String qq = pNamedQueryDefinition.getQueryString();
HQLQueryPlan plan = queryPlanCache.getHQLQueryPlan(
pNamedQueryDefinition.getQuery(), false,
enabledFilters);
String query = plan.getSqlStrings()[0];
log.info(" HQL : " + pNamedQueryDefinition.getQuery());
log.info(" SQL : " + query);
Connection connection = ((SessionImpl) em.getDelegate())
.connection();
Statement ps = connection.createStatement();
ps.execute("explain plan for " + query + "");
}