java - @NamedQuery : identification variable 'sysdate' is not defined in the FROM clause

标签 java jpa named-query

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

我正在使用此 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)")

这里我希望列 desactivateDate 为 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

最佳答案

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

关于java - @NamedQuery : identification variable 'sysdate' is not defined in the FROM clause,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62046658/

相关文章:

Java 实体日期字段和 Oracle TIMESTAMP 数据类型

java.util.Date/JodaTime : Given a java. util.Date,生成给定日期的开始和结束

java - 是否可以使用@Transactional 测量所有 Spring 管理的事务的时间?

mysql - 组织.hibernate.MappingException : Named query not known

java - 为 armeabi 编译的文件是否有 armeabi-v7a 的一些问题

java - Java 是 "pass-by-reference"还是 "pass-by-value"?

java - 未报告 IOException 错误,但有 "throws Exception"并且 Try 和 Catch 位于方法内

java - 更改 hbase 时间戳排序以获得特定行的第一个版本

java - 带有 resultClass 参数的 NamedQuery 未返回查询结果的预期 "type"

java - 即使未定义 `queryResultList`,JPA 也会限制 `setMaxResults`