我試圖獲取兩個日期之間的行數。 第一個日期是今天,第二個日期是15天前。兩天之間的休眠條件
Criteria criteria = session.createCriteria(Order.class);
Calendar c15DaysAgo = Calendar.getInstance(); // 15 days ago
c15DaysAgo.add(Calendar.DAY_OF_YEAR, -15);
Calendar today = Calendar.getInstance(); // today
today.add(Calendar.DAY_OF_YEAR, 0);
criteria.add(Expression.between("orderTime", today, c15DaysAgo));
totalCount = (Integer) criteria.setProjection(Projections.rowCount()).uniqueResult();
我得到這個異常:
java.lang.ClassCastException: java.util.GregorianCalendar cannot be cast to java.util.Date
at org.hibernate.type.TimestampType.toString(TimestampType.java:55)
at org.hibernate.type.NullableType.nullSafeToString(NullableType.java:93)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:140)
at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:116)
at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1707)
at org.hibernate.loader.Loader.bindParameterValues(Loader.java:1678)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1563)
at org.hibernate.loader.Loader.doQuery(Loader.java:673)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2220)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
at org.hibernate.loader.Loader.list(Loader.java:2099)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:94)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1569)
at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
at org.hibernate.impl.CriteriaImpl.uniqueResult(CriteriaImpl.java:305)
有一些方法可以讓我做算什麼?
記住四捨五入(截斷/上限)日期。 – lschin 2011-05-12 02:19:28