I am trying to group several months by month using HQL, but I am a little new to this API and cannot make it work.
Here is my code:
Criteria query = getHibernateSession().createCriteria(SalesPerformance.class);
query.setProjection(Projections.projectionList().add(
Projections.groupProperty("effectiveDate"), "effectiveDate").add(
Projections.groupProperty("primaryKey.seller", "seller").add(
Projections.sum("totalSales"))));
query.add(Property.forName("primaryKey.seller.id").eq(sellerId)).setFetchMode(
"primaryKey.seller", FetchMode.SELECT);
query.add(Property.forName("primaryKey.effectiveDate").le(new Date()));
query.add(Property.forName("primaryKey.effectiveDate").ge(DateUtils.truncate(new Date(), Calendar.MONTH)));
query.addOrder(Order.desc("primaryKey.effectiveDate"));
return query.list();
My problem with this query is that it will return one row per day when I need one row per month due to Projections.groupProperty ("effectiveDate").
I thought about using Projections.sqlGroupProjection instead of Projections.groupProperty and threw it into some HQL, but the documentation and steam examples I found didn’t really help me understand how I would like to put the correct postresql statement in this method.
Anyone who knows about Postgres and HQL can give some hints here, please?