HQL を使用していくつかの行を月ごとにグループ化しようとしていますが、その API は初めてで、うまく動作しないようです。
これが私のコードです:
Criteria query = getHibernateSession().createCriteria(SalesPerformance.class);
// summary report is grouped by date
query.setProjection(Projections.projectionList().add(
Projections.groupProperty("effectiveDate"), "effectiveDate").add(
Projections.groupProperty("primaryKey.seller", "seller").add(
Projections.sum("totalSales"))));
// sub-select based on seller id
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();
このクエリに関する私の問題は、Projections.groupProperty("effectiveDate") のために、1 か月に 1 行が必要なときに、1 日 1 行を返すことです。
Projections.groupProperty の代わりに Projections.sqlGroupProjection を使用して、いくつかの HQL を投入することを考えましたが、ドキュメントと私が見つけたいくつかの例は、そのメソッドに正しい postresql ステートメントを配置する方法を理解するのに実際には役立ちませんでした。
Postgres と HQL について知っている人は、ここでヒントを教えてください。