表达式中的运算符[platform operator - DateDifference]无效

时间:2017-01-27 10:53:33

标签: java eclipselink jpql

我正在使用2.6.4 Eclipse Link和MariaDB。该文档列出了几个运算符,可以在编写查询时使用。 “DateDifference”也是一个例子。

文档:

https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#OPERATOR

JPQL:

SELECT a.cdOrdem FROM Ordem a 
WHERE a.status.cdStatus = :cdStatus AND OPERATOR('DateDifference',CURRENT_DATE,'day',a.dtOrdem) > :qtdDeDias

输出:

    ADVERTÊNCIA: 
Exception Description: Invalid operator [platform operator - DateDifference] in expression.
Query: ReportQuery(referenceClass=Ordem jpql="SELECT a.cdOrdem FROM Ordem a WHERE a.status.cdStatus = :cdStatus AND OPERATOR('DateDifference',CURRENT_DATE,'day',a.dtOrdem) > :qtdDeDias")
Local Exception Stack: 
Exception [EclipseLink-6047] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.QueryException
Exception Description: Invalid operator [platform operator - DateDifference] in expression.
Query: ReportQuery(referenceClass=Ordem jpql="SELECT a.cdOrdem FROM Ordem a WHERE a.status.cdStatus = :cdStatus AND OPERATOR('DateDifference',CURRENT_DATE,'day',a.dtOrdem) > :qtdDeDias")
    at org.eclipse.persistence.exceptions.QueryException.invalidOperator(QueryException.java:665)
    at org.eclipse.persistence.internal.expressions.FunctionExpression.initializePlatformOperator(FunctionExpression.java:330)
    at org.eclipse.persistence.internal.expressions.FunctionExpression.getPlatformOperator(FunctionExpression.java:307)
    at org.eclipse.persistence.internal.expressions.FunctionExpression.printSQL(FunctionExpression.java:544)
    at org.eclipse.persistence.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:2234)
    at org.eclipse.persistence.internal.expressions.CompoundExpression.printSQL(CompoundExpression.java:286)
    at org.eclipse.persistence.internal.expressions.RelationExpression.printSQL(RelationExpression.java:899)
    at org.eclipse.persistence.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:2239)
    at org.eclipse.persistence.internal.expressions.CompoundExpression.printSQL(CompoundExpression.java:286)
    at org.eclipse.persistence.expressions.ExpressionOperator.printDuo(ExpressionOperator.java:2234)
    at org.eclipse.persistence.internal.expressions.CompoundExpression.printSQL(CompoundExpression.java:286)
    at org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter.translateExpression(ExpressionSQLPrinter.java:325)
    at org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter.printExpression(ExpressionSQLPrinter.java:129)
    at org.eclipse.persistence.internal.expressions.SQLSelectStatement.printSQL(SQLSelectStatement.java:1755)
    at org.eclipse.persistence.internal.databaseaccess.DatabasePlatform.printSQLSelectStatement(DatabasePlatform.java:3247)
    at org.eclipse.persistence.platform.database.MySQLPlatform.printSQLSelectStatement(MySQLPlatform.java:730)
    at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:843)
    at org.eclipse.persistence.internal.expressions.SQLSelectStatement.buildCall(SQLSelectStatement.java:854)
    at org.eclipse.persistence.descriptors.ClassDescriptor.buildCallFromStatement(ClassDescriptor.java:815)
    at org.eclipse.persistence.internal.queries.StatementQueryMechanism.setCallFromStatement(StatementQueryMechanism.java:390)
    at org.eclipse.persistence.internal.queries.ExpressionQueryMechanism.prepareReportQuerySelectAllRows(ExpressionQueryMechanism.java:1698)
    at org.eclipse.persistence.queries.ReportQuery.prepareSelectAllRows(ReportQuery.java:1207)
    at org.eclipse.persistence.queries.ReadAllQuery.prepare(ReadAllQuery.java:816)
    at org.eclipse.persistence.queries.ReportQuery.prepare(ReportQuery.java:1075)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:666)
    at org.eclipse.persistence.queries.ObjectLevelReadQuery.checkPrepare(ObjectLevelReadQuery.java:911)
    at org.eclipse.persistence.queries.DatabaseQuery.checkPrepare(DatabaseQuery.java:615)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:194)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:116)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:102)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:86)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1614)
    at br.com.lohr.library.java.dao.FuncaoDAO.funcaoAHParte1(FuncaoDAO.java:191)
    at br.com.lohr.monitor.scpl.funcoes.FuncaoAH.run(FuncaoAH.java:41)
    at java.lang.Thread.run(Thread.java:745)

如何使用等于SQL DateDiff的日期生成JPQL查询?

0 个答案:

没有答案