我的SQL查询
SELECT count(1),trunc(D_O_I) FROM TableName
WHERE P_D IN (3) AND
D_O_I BETWEEN to_date('01/01/2014','mm/dd/yyyy') and to_date('01/31/2015','mm/dd/yyyy') group by trunc(D_O_I)
我的Hibernate查询代码如下:
session = HibernateSessionFactory.getSessionFactory().openSession();
Criteria criteria = session.createCriteria(TableName.class).setProjection(Projections.projectionList()
.add(Projections.groupProperty("dteOfIss"), "dteOfIssResult").add(Projections.rowCount(), "count")).setResultTransformer(Transformers.aliasToBean(GroupedDateDTO.class));
criteria.add(Restrictions.sqlRestriction("(P_D IN ('3'))"));
if (reportsForm.getFromDate() != null && reportsForm.getToDate() != null) {
criteria.add(Restrictions.sqlRestriction("trunc(D_O_I) >= to_date('"+ utils.convertDateToString(reportsForm.getFromDate()) + "', 'MM/dd/yyyy')"));
criteria.add(Restrictions.sqlRestriction("trunc(D_O_I) <= to_date('"+ utils.convertDateToString(reportsForm.getToDate()) + "', 'MM/dd/yyyy')"));
}
listResult = criteria.list();
如何在hibernate代码中将Trunc添加到dteofIss?我尝试了不同的方式,但我无法取得。
请帮助