【问题标题】:SQL for NamedQuery in EclipseLinkEclipseLink 中 NamedQuery 的 SQL
【发布时间】:2023-03-31 05:37:01
【问题描述】:

我想在Eclipselink 中将以下查询写为NamedQuery

   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)

问候,

【问题讨论】:

    标签: jpa eclipselink


    【解决方案1】:

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

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

    【讨论】:

    • 感谢 FUNC 解决了我的问题。以下是工作namedquery select o from user o where FUNC('trunc',o.trsf_date) = ?1 and o.contrno in(?2,?3,?4,?5,?6,?7,?8, ?9,?10,?11)
    猜你喜欢
    • 2012-07-18
    • 2013-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-07
    • 2013-10-09
    • 2012-07-24
    相关资源
    最近更新 更多