2012-04-13 181 views
1

我的錯誤在哪裏?JPQL間隔日期

SELECT m FROM Message m WHERE m.tabId = :idTab AND BETWEEN :startDate AND :endDate ORDER BY m.id DESC 

我有此錯誤:

Exception Description: Syntax error parsing the query ... , line 1, column 63: unexpected token [BETWEEN]. 
Internal Exception: NoViableAltException([email protected][634:7: (n= NOT)?]) 

在我的Java代碼,我有:

// Exception line 
Query query = em.createQuery(queryBuilder.toString()); 
//// 
query.setParameter("idTab", idTablet); 
if (limit > 0) { 
    query.setMaxResults(limit); 
} 
if (dateFrom != null) { 
    query.setParameter("startDate", dateFrom, TemporalType.DATE); 
    if (dateTo == null) { 
    dateTo = new Date(); 
    } 
    query.setParameter("endDate", dateTo, TemporalType.DATE); 
} 
messages = (List<MessageEntity>) query.getResultList(); 
+0

你確定它不是SELECT *? – Ushox 2012-04-13 10:05:36

回答

1

您不選擇任何字段,你缺少的字段中輸入日期比較。嘗試 -

SELECT m.* 
FROM Message m 
WHERE m.tabId = :idTab 
AND date_field BETWEEN :startDate AND :endDate 
ORDER BY m.id DESC 
+0

你是對的,謝謝! – CeccoCQ 2012-04-13 10:15:47

+0

我接受了,謝謝! – CeccoCQ 2012-04-16 11:02:37