1

我正在执行单元测试并不断收到以下代码的此错误:

java.lang.IllegalArgumentException: An exception occurred while creating a query in EntityManager: 
Exception Description: Syntax error parsing [SELECT t1 FROM Test1 t1, Test1Rel t1r, Type tp  WHERE ( sysdate >= t1.sdate and sysdate <= t1.edate ) OR ( t1.sdate <= sysdate AND t1.edate is null ) AND t1r.Test1Id = t1.Test1Id AND t1.relTpId = tp.TypeId and t1.isActv = 1 AND t1r.isActv = 1 AND tp.shrtCode = :shrtCode AND t1r.custId = :custId]. 
[69, 163] The expression is not a valid conditional expression.
[164, 330] The query contains a malformed ending.
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1512)
    at com.etiya.mts.data.dao.newpac.dao.ProductOfferDAO.findTest1(ProductOfferDAO.java:821)
    at com.etiya.mts.data.dao.newpac.service.ProductOfferService.findTest1(ProductOfferService.java:241)
    at com.etiya.mts.rules.productoffering.Test1Controller.execute(Test1Controller.java:36)
    at com.etiya.mts.ejb.BasketValidateBean.validateBasket(BasketValidateBean.java:108)
    at com.etiya.mts.ejb.RuleManager.validateBasket(RuleManager.java:887)
    at com.etiya.mts.ejb.BasketValidateBeanTest.validaBasketTest(BasketValidateBeanTest.java:210)
    at com.etiya.mts.ejb.BasketValidateBeanTest.basketValidateBeanTest(BasketValidateBeanTest.java:57)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Syntax error parsing [SELECT t1 FROM Test1 t1, Test1Rel t1r, Type tp  WHERE ( sysdate >= t1.sdate and sysdate <= t1.edate ) OR ( t1.sdate <= sysdate AND t1.edate is null ) AND t1r.Test1Id = t1.Test1Id AND t1.relTpId = tp.TypeId and t1.isActv = 1 AND t1r.isActv = 1 AND tp.shrtCode = :shrtCode AND t1r.custId = :custId]. 
[69, 163] The expression is not a valid conditional expression.
[164, 330] The query contains a malformed ending.
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:150)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:325)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:270)
    at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:157)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:138)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.buildEJBQLDatabaseQuery(EJBQueryImpl.java:112)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:98)
    at org.eclipse.persistence.internal.jpa.EJBQueryImpl.<init>(EJBQueryImpl.java:82)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1510)
    ... 31 more
String cqString = "SELECT t1 FROM Test1 t1, Test1Rel t1r, Type tp" +
                "  WHERE ( sysdate >= t1.sdate and sysdate <= t1.edate )" +
                " OR ( t1.sdate <= sysdate AND t1.edate is null )" +
                " AND t1r.Test1Id = t1.Test1Id" + 
                " AND t1.relTpId = tp.TypeId" +
                " and t1.isActv = 1" +
                " AND t1r.isActv = 1" + 
                " AND tp.shrtCode = :shrtCode" +
                " AND t1r.custId = :custId";
        Query cq = getEntityManager().createQuery(cqString); 
        cq.setParameter("shrtCode", ofrRuleTpShrtCode);
        cq.setParameter("custId", custId);

如果我将代码更改为:

StringBuilder query = new StringBuilder();
        query.append("SELECT * FROM Test1 t1,Test1_REL t1r,Type tp ");
        query.append("WHERE (sysdate between t1.SDATE and t1.EDATE) OR (t1.sdate <= sysdate AND t1.edate is null) ");
        query.append("AND t1r.CUST_OFR_RULE_ID=t1.CUST_OFR_RULE_ID ");
        query.append("AND t1.REL_TP_ID=tp.GNL_TP_ID and t1.IS_ACTV=1 ");
        query.append("AND t1r.IS_ACTV=1 AND tp.SHRT_CODE = ? AND t1r.CUST_ID = ? ");
        Query cq = getEntityManager().createNativeQuery(query.toString()); 
        cq.setParameter(1, shrtCode);
        cq.setParameter(2, custId);

我没有任何例外。奇怪的是这段代码在其他环境中工作,但不是我的。它看起来像一个语法错误,但我在使用 createQuery 的代码的其他部分中不断收到此错误。

我检查了 Maven 的存储库,但它是最新的。有人对这个问题有任何意见吗?

编辑:我将 eclipselink 版本从 2.4.0 更改为 2.5.0,但仍然出现相同的错误。它可以像windows的语言设置一样吗?

在此处输入图像描述

4

2 回答 2

1

您使用的是哪个 EclipseLink 版本?您可能遇到了这个错误,它已在 2.4.3 版中得到解决。看起来问题出在 Hermes 查询解析器上。

于 2014-12-04T15:31:35.357 回答
1

我更改了系统语言、区域设置和格式信息。有效。

于 2014-12-05T09:06:26.800 回答