title: JPA Criteria Query API for Select New
body: <p>I have to construct a Criteria Query for a use case where the output would be like..</p>
  
  <p>select new WrapperXXXYYY(XXX.something, YYY.something) from XXX x, YYY y, where x.id = y.createdBy and ...</p>
  
  <p>The Code that I created is..and the domain class here is Just a wrapper of other two Entity classes.</p>
  
  <pre><code>    CriteriaBuilder builder = em.getCriteriaBuilder();
      CriteriaQuery&lt;? extends T&gt;  criteriaQuery = builder.createQuery(domainClass);
  
      Root&lt;JPAUser&gt; user = criteriaQuery.from(JPAUser.class);
      Root&lt;JPAReport&gt; report = criteriaQuery.from(JPAReport.class);
      criteriaQuery.multiselect(builder.construct(domainClass, user.get("surrogateId"), report.get("projectId")));
      return  em.createQuery(criteriaQuery);
  </code></pre>
  
  <p>I'm getting the below Exception 
  "javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: new near line 1, column 62  "</p>
  
  <p>and the generated query is - 
  [select new com.collabnet.ctf.server.report.jpa.JPAReportList(new com.collabnet.ctf.server.report.jpa.JPAReportList(generatedAlias0.surrogateId, generatedAlias1.projectId)) from com.collabnet.ctf.server.user.jpa.JPAUser as generatedAlias0, com.collabnet.ctf.server.report.jpa.JPAReport as generatedAlias1]</p>
  
  <p>I see there a two "new" statements for domainClass, what is going wrong with the syntax?</p>