EclipseLink中的NamedQuery SQL

时间:2011-12-08 11:46:18

标签: jpa eclipselink

我想在NamedQuery

中将以下查询写为Eclipselink
   select o  from user o where trunc(o.TRSF_DATE) = ?1 and o.contrno in(?2,?3,?4,?5,?6,?7,?8,?9,?10,?11)

我收到以下错误

   Internal Exception: NoViableAltException(83!=[661:1: simpleConditionalExpressionRemainder[Object left] returns [Object node] : (n= compariso
nExpression[left] | (n1= NOT )? n= conditionWithNotExpression[(n1!=null), left] | IS (n2= NOT )? n= isExpression[(n2!=null), left] );])
        at org.eclipse.persistence.exceptions.JPQLException.unexpectedToken(JPQLException.java:372)

此致

1 个答案:

答案 0 :(得分:3)

我的猜测是错误是由trunc引起的,而trunc不是有效的JPQL函数。在EclipseLink中,您可以使用FUNC关键字来调用数据库函数。

请参阅, http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Support_for_Native_Database_Functions