我想按時間選擇實體。 我有包含日期和時間的字段類型爲DATE的Oracle DBMS。這是我的代碼。如何按時間標準選擇數據?使用Hibernate Criteria和Oracle,什麼是更好的工作方式?
Calendar timeCal = new GregorianCalendar(0,0,0,0,0,0);
Date timeMin = timeCal.getTime();
timeCal.add(Calendar.HOUR_OF_DAY, 1);
Date timeMax = timeCal.getTime();
if (minDate != null && maxDate != null)
criteria.add(Restrictions.between("eventDate", minDate, maxDate));
if (onDate != null) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(onDate);
calendar.add(Calendar.DAY_OF_MONTH, 1);
criteria.add(Restrictions.between("eventDate", onDate, calendar.getTime()));
}
if(minTime!=null&&maxTime!=null){
/*
How to add Restriction on eventDate field, for time only?
if minTime is 3:00 and maxTime is 16:00, must to return
all rows having the time part of their eventDate between
3:00 and 16:00, regardless of the date part
*/
}
您發佈的代碼有什麼問題? – 2012-01-16 07:25:23
未執行minTime!= null && maxTime!= null表達式 – Selector 2012-01-16 07:28:26
我們不知道這些標準是什麼,以及查詢應該執行什麼操作。 – 2012-01-16 07:30:16