【问题标题】:@NamedQuery : identification variable 'sysdate' is not defined in the FROM clause@NamedQuery : FROM 子句中未定义标识变量“sysdate”
【发布时间】:2020-05-27 15:19:10
【问题描述】:

我试图寻找它,但无法解决。需要你的想法

我正在使用这个 NamedQuery 从数据库中获取结果。

@NamedQuery(name= "Person.FindByCodeAndFiscalYear", 
            query="select o from Person o where o.fiscalYear=:pfiscalYear and o.Code=:pCode and (o.desactivatedDate is null or o.desactivatedDate > sysdate)")

我希望列 deactivateDate 为 null 或 sysdate

编译代码时出错:

Caused By: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [select o from Person o where o.fiscalYear=:pfiscalYear and o.Code=:pCode and (o.desactivatedDate is null or o.desactivatedDate > sysdate)]. 
[144, 151] The identification variable 'sysdate' cannot be used in conjunction with the > operator.
[144, 151] The identification variable 'sysdate' is not defined in the FROM clause.
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:155)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:347)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:278)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:163)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:142)
    at org.eclipse.persistence.internal.jpa.JPAQuery.processJPQLQuery(JPAQuery.java:221)
    at org.eclipse.persistence.internal.jpa.JPAQuery.prepare(JPAQuery.java:182)
    at org.eclipse.persiste

【问题讨论】:

  • 谢谢各位,找到答案了。我们可以使用 CURRENT_DATE 代替 sysdate

标签: java jpa named-query


【解决方案1】:

SYSDATA 是 Oracle 特定的,而 CURRENT_DATA 是 SQL 和 JPQL 标准。

【讨论】:

    猜你喜欢
    • 2021-08-17
    • 2015-09-24
    • 1970-01-01
    • 2015-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-30
    相关资源
    最近更新 更多