Dynamic Scalar Sub Queries <p>How to generate Scalar Sub Queries dynamically at run time using Java. Please suggest any api if available?</p> <p>Scalar sub query example:</p> <pre><code>SELECT d.deptno, d.dname, (SELECT count(*) FROM emp e WHERE e.deptno = d.deptno) AS "Num Dept" FROM dept d; </code></pre> <p>For example take hotel reservation application. user can search on different criteria. I want to construct scalar subquery based on this criteria.</p> <p>Can we do this in Hibernate Criteria API or JPA 2.0 Criteria API. But I want to use native SQL in my DAO....</p>