title: Using Projections in JPA 2
body: <p>I need to convert a Hibernate criteria query like the following</p>
  
  <pre><code>curList = session.createCriteria(Islem.class)
                      .createAlias("workingDay", "d")
                      .setProjection(Projections.sum("amount"))
                      .add(Restrictions.eq("currency", CURRENCY))
                      .add(Restrictions.eq("product", product))
                      .add(Restrictions.ne("status", INACTIVE))
                      .add(Restrictions.eq("d.status", ACTIVE))
                      .getResultList();
  </code></pre>
  
  <p>However in JPA (2) I have no idea how to implement the projection - in this case - the sum. It's odd that Hibernate and JPA (even Hibernate JPA 2) have this tremendous differences especially in criteria queries.</p>
  
  <p>I start by </p>
  
  <pre><code>CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery&lt;Islem&gt; cq = cb.createQuery(Islem.class);
  Root&lt;Islem&gt; isr = cq.from(Islem.class);
  cq.select(isr).where(cb.equal(isr.get("currency"), CURRENCY), 
                       cb.notEqual(isr.get("status"), INACTIVE),
                       cb.equal(isr.get("product"), product));
  </code></pre>
  
  <p>however have no idea how to implement the projection here neither the alias</p>