java.lang.IllegalArgumentException

1.2k Views Asked by At

I am executing a unit test and keep getting this error for the following code:

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);

If I change the code to this:

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);

I don't get any exception. The strange thing is this code works in other environments, but not mine. It looks like a syntax error, but I keep getting this error in other parts of the code where createQuery is used.

I checked the maven's repository but it is up to date. Does any one have any opinion about this issue?

Edit: I changed the eclipselink version from 2.4.0 to 2.5.0 but still getting the same error. Can it be something like a language setting of windows?

enter image description here

2

There are 2 best solutions below

3
On

Which EclipseLink version are you using? You might be hitting this bug, it is resolved in version 2.4.3. Looks like the problem is with Hermes query parser.

1
On

I changed system language, locale and format information. It worked.