SQL for NamedQuery in EclipseLink

2019-08-22 09:45发布

I want to write following query as NamedQuery in 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)

I am getting following error

   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)

Regards,

1条回答
时光不老,我们不散
2楼-- · 2019-08-22 10:06

My guess is that the error is caused by trunc, which is not a valid JPQL function. In EclipseLink you can use the FUNC keyword to call a database function.

See, http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/Support_for_Native_Database_Functions

查看更多
登录 后发表回答