你試過Projections.sqlProjection這樣
session.createCriteria(Exam.class)
.setProjection(Projections.projectionList()
.add(Projections.sqlProjection("date(beginExam) as beginDate", new String[] { "beginDate" }, new Type[] { StandardBasicTypes.DATE }))
.add(Projections.groupProperty("beginDate")))
.list();
或Projections.sqlGroupProjection這樣
session.createCriteria(Exam.class)
.setProjection(Projections.sqlGroupProjection("date(beginExam) as beginDate", "beginDate", new String[] { "beginDate" }, new Type[] { StandardBasicTypes.DATE }))
.list();
休眠基因在SQL查詢費率表的別名,所以你可能需要將{alias}
片段添加到您的SQL片段來完成這項工作:
session.createCriteria(Exam.class)
.setProjection(Projections.projectionList()
.add(Projections.sqlProjection("date({alias}.beginExam) as beginDate", new String[] { "beginDate" }, new Type[] { StandardBasicTypes.DATE }))
.add(Projections.groupProperty("beginDate")))
.list();
或SQLGroupProjection
:
session.createCriteria(Exam.class)
.setProjection(Projections.sqlGroupProjection("date({alias}.beginExam) as beginDate", "beginDate", new String[] { "beginDate" }, new Type[] { StandardBasicTypes.DATE }))
.list();
我做到了,徹底。在衆多的eq方法和之間,沒有方法可以將列的值轉換爲日期,因此可以將其比較或放入groupProperty中。 – user996088
@ user996088:beginExam的數據類型是什麼?你可以在Projections.sqlProjection中使用_any_ SQL,所以我不明白你爲什麼不能把它轉換成日期。 – tscho
我的錯。在我的焦慮中,我沒有意識到,卡卡瑪用錯誤的聯繫指引了我正確的方向。 – user996088