Get native SQL from QueryDSL JPA (JPAQuery or JPQLQuery)
<p>I have a requirement to count the number of group by records for pagination purpose. For example:  </p>

<pre><code>select count(*) from ( 
    select name, count(id) from customer
    group by name
);
</code></pre>

<p>However it couldn't be achieved via QueryDSL due to the limitation of JPA 
where JPQL doesn't allows to select count from sub query. </p>

<p>Is it possible to get the native SQL from QueryDSL JPAQuery or JPQLQuery? My plan  is to construct and execute the select count native SQL statement via EntityManager.</p>

<pre><code>String subQueryNativeSQL = "..."; // native SQL from QueryDSL
Query q = em.createNativeQuery("select count(*) from (" + subQueryNativeSQL + ")");
long count = (long) q.getSingleResult();
</code></pre>