我正在执行单元测试并继续为以下代码获取此错误:
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的语言设置吗?
答案 0 :(得分:1)
您使用的是哪个EclipseLink版本?您可能正在点击this bug,它已在版本2.4.3中得到解决。看起来问题出在Hermes查询解析器上。
答案 1 :(得分:1)
我更改了系统语言,语言环境和格式信息。它奏效了。