title: Group by month with criteria in Hibernate
body: <p>I'm trying to get a report using Criteria and ProjectionList, and I'm pretty new using this through hibernate. 
  So I have this model:</p>
  
  <pre><code>private Long _userId;
  
   private Category _category;
  
   private Long _companyId;
  
   private Double _amount;
  
   private Date _date;
  </code></pre>
  
  <p>And I building the query using this:</p>
  
  <pre><code>  public List sumPaymentsByUserCategoryPeriod(Category category, Long userId,Integer period){
    GregorianCalendar from = new GregorianCalendar();
    from.add(Calendar.MONTH, -period);
    List&lt;CategoryAmount&gt; resultDTO= new ArrayList&lt;CategoryAmount&gt;();
  
    Criteria criteria = getSession().createCriteria(Payment.class);
    criteria.add(Restrictions.eq("_category", category));
    criteria.add(Restrictions.eq("_userId",userId));
    criteria.add(Restrictions.between("_date", from.getTime(), new Date()));
  
    ProjectionList projectionList = Projections.projectionList();
    projectionList.add(Projections.sum("_amount"));
    projectionList.add(Projections.groupProperty("_date"));
    criteria.setProjection(projectionList);
    return  criteria.list();
  
   }
  </code></pre>
  
  <p>Basically this method receive a Category and a userId to filter the payments records and a period, who will indicate how many months from now to back I want to sum. How can I get the sum result grouped by months?</p>
  
  <p>Any help or tip I'll appreciate it!</p>