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:
private Long _userId;
You can use an SQLQuery in hibernate, here is an example:
public List groupByMonth(ChartRequest request){
SQLQuery query = getSession().createSQLQuery("SELECT \n" +
"sum(this_.amount) as amount, \n" +
"extract(month from this_.fecha) as month, \n" +
"extract(year from this_.fecha) as year\n" +
"FROM jornada this_ \n" +
"GROUP BY \n" +
"month, \n" +
"year \n" +
"ORDER BY \n" +
"year asc, \n" +
"month asc");
query.setResultTransformer(Transformers.aliasToBean(MonthlyPoint.class));
return query.list();
}
public class MonthlyPoint {
private Double year;
private Double month;
private Double amount;
//-- getters and setters here --
}