java - Constant interpreted as expression in QueryDSL -
i have following query:
dateexpression<date> enddateplus7 = datetemplate.create(date.class, "date_add({0},interval {1} day)", buy.enddate, expressions.constant(7)); booleanexpression exp = ad.brandsurveytype.ne(brandsurveytype.none).and((buy.status.eq(newbuystatus.closed).and(buy.enddate.after(enddateplus7))).not()); query.where(exp);
when looking query string generated, querydsl interprets "7" constant expression evaluated , following error produced:
line 4:113: unexpected token: ? @ org.hibernate.hql.internal.antlr.hqlbaseparser.identprimary(hqlbaseparser.java:4016) @ org.hibernate.hql.internal.antlr.hqlbaseparser.primaryexpression(hqlbaseparser.java:859) @ org.hibernate.hql.internal.antlr.hqlbaseparser.atom(hqlbaseparser.java:3390) @ org.hibernate.hql.internal.antlr.hqlbaseparser.unaryexpression(hqlbaseparser.java:3168) @ org.hibernate.hql.internal.antlr.hqlbaseparser.multiplyexpression(hqlbaseparser.java:3040) @ org.hibernate.hql.internal.antlr.hqlbaseparser.additiveexpression(hqlbaseparser.java:2750) @ org.hibernate.hql.internal.antlr.hqlbaseparser.concatenation(hqlbaseparser.java:568) @ org.hibernate.hql.internal.antlr.hqlbaseparser.relationalexpression(hqlbaseparser.java:2518) @ org.hibernate.hql.internal.antlr.hqlbaseparser.equalityexpression(hqlbaseparser.java:2379) @ org.hibernate.hql.internal.antlr.hqlbaseparser.negatedexpression(hqlbaseparser.java:2343) @ org.hibernate.hql.internal.antlr.hqlbaseparser.logicalandexpression(hqlbaseparser.java:2259) @ org.hibernate.hql.internal.antlr.hqlbaseparser.logicalorexpression(hqlbaseparser.java:2224) @ org.hibernate.hql.internal.antlr.hqlbaseparser.expression(hqlbaseparser.java:2010) @ org.hibernate.hql.internal.antlr.hqlbaseparser.exprlist(hqlbaseparser.java:3785) @ org.hibernate.hql.internal.antlr.hqlbaseparser.identprimary(hqlbaseparser.java:3939) @ org.hibernate.hql.internal.antlr.hqlbaseparser.primaryexpression(hqlbaseparser.java:859) @ org.hibernate.hql.internal.antlr.hqlbaseparser.atom(hqlbaseparser.java:3390) @ org.hibernate.hql.internal.antlr.hqlbaseparser.unaryexpression(hqlbaseparser.java:3168) @ org.hibernate.hql.internal.antlr.hqlbaseparser.multiplyexpression(hqlbaseparser.java:3040) @ org.hibernate.hql.internal.antlr.hqlbaseparser.additiveexpression(hqlbaseparser.java:2750) @ org.hibernate.hql.internal.antlr.hqlbaseparser.relationalexpression(hqlbaseparser.java:2599) @ org.hibernate.hql.internal.antlr.hqlbaseparser.equalityexpression(hqlbaseparser.java:2379) @ org.hibernate.hql.internal.antlr.hqlbaseparser.negatedexpression(hqlbaseparser.java:2343) @ org.hibernate.hql.internal.antlr.hqlbaseparser.logicalandexpression(hqlbaseparser.java:2269) @ org.hibernate.hql.internal.antlr.hqlbaseparser.logicalorexpression(hqlbaseparser.java:2224) @ org.hibernate.hql.internal.antlr.hqlbaseparser.expression(hqlbaseparser.java:2010) @ org.hibernate.hql.internal.antlr.hqlbaseparser.expressionorvector(hqlbaseparser.java:4286) @ org.hibernate.hql.internal.antlr.hqlbaseparser.primaryexpression(hqlbaseparser.java:943) @ org.hibernate.hql.internal.antlr.hqlbaseparser.atom(hqlbaseparser.java:3390) @ org.hibernate.hql.internal.antlr.hqlbaseparser.unaryexpression(hqlbaseparser.java:3168) @ org.hibernate.hql.internal.antlr.hqlbaseparser.multiplyexpression(hqlbaseparser.java:3040) @ org.hibernate.hql.internal.antlr.hqlbaseparser.additiveexpression(hqlbaseparser.java:2750) @ org.hibernate.hql.internal.antlr.hqlbaseparser.concatenation(hqlbaseparser.java:568) @ org.hibernate.hql.internal.antlr.hqlbaseparser.relationalexpression(hqlbaseparser.java:2518) @ org.hibernate.hql.internal.antlr.hqlbaseparser.equalityexpression(hqlbaseparser.java:2379) @ org.hibernate.hql.internal.antlr.hqlbaseparser.negatedexpression(hqlbaseparser.java:2343) @ org.hibernate.hql.internal.antlr.hqlbaseparser.negatedexpression(hqlbaseparser.java:2303) @ org.hibernate.hql.internal.antlr.hqlbaseparser.logicalandexpression(hqlbaseparser.java:2269) @ org.hibernate.hql.internal.antlr.hqlbaseparser.logicalorexpression(hqlbaseparser.java:2224) @ org.hibernate.hql.internal.antlr.hqlbaseparser.expression(hqlbaseparser.java:2010) @ org.hibernate.hql.internal.antlr.hqlbaseparser.logicalexpression(hqlbaseparser.java:1786) @ org.hibernate.hql.internal.antlr.hqlbaseparser.whereclause(hqlbaseparser.java:452) @ org.hibernate.hql.internal.antlr.hqlbaseparser.queryrule(hqlbaseparser.java:706) @ org.hibernate.hql.internal.antlr.hqlbaseparser.selectstatement(hqlbaseparser.java:294) @ org.hibernate.hql.internal.antlr.hqlbaseparser.statement(hqlbaseparser.java:157) @ org.hibernate.hql.internal.ast.querytranslatorimpl.parse(querytranslatorimpl.java:266) @ org.hibernate.hql.internal.ast.querytranslatorimpl.docompile(querytranslatorimpl.java:180) @ org.hibernate.hql.internal.ast.querytranslatorimpl.compile(querytranslatorimpl.java:136) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:105) @ org.hibernate.engine.query.spi.hqlqueryplan.<init>(hqlqueryplan.java:80) @ org.hibernate.engine.query.spi.queryplancache.gethqlqueryplan(queryplancache.java:168) @ org.hibernate.internal.abstractsessionimpl.gethqlqueryplan(abstractsessionimpl.java:219) @ org.hibernate.internal.abstractsessionimpl.createquery(abstractsessionimpl.java:197) @ org.hibernate.internal.sessionimpl.createquery(sessionimpl.java:1732) @ org.hibernate.ejb.abstractentitymanagerimpl.createquery(abstractentitymanagerimpl.java:291) @ sun.reflect.generatedmethodaccessor67.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.orm.jpa.extendedentitymanagercreator$extendedentitymanagerinvocationhandler.invoke(extendedentitymanagercreator.java:365) @ $proxy64.createquery(unknown source) @ sun.reflect.generatedmethodaccessor67.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.orm.jpa.sharedentitymanagercreator$sharedentitymanagerinvocationhandler.invoke(sharedentitymanagercreator.java:240) @ $proxy64.createquery(unknown source) @ com.mysema.query.jpa.impl.abstractjpaquery.createquery(abstractjpaquery.java:134) @ com.mysema.query.jpa.impl.abstractjpaquery.createquery(abstractjpaquery.java:103) @ com.mysema.query.jpa.impl.abstractjpaquery.list(abstractjpaquery.java:271) @ mycomp.repository.interfaces.buyrepositoryimpl.getbuyswithbrandsurveyads(buyrepositoryimpl.java:54) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:319) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:183) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:155) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:155) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:202) @ $proxy110.getbuyswithbrandsurveyads(unknown source) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.executemethodon(repositoryfactorysupport.java:334) @ org.springframework.data.repository.core.support.repositoryfactorysupport$queryexecutormethodinterceptor.invoke(repositoryfactorysupport.java:309) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.transaction.interceptor.transactioninterceptor.invoke(transactioninterceptor.java:110) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.dao.support.persistenceexceptiontranslationinterceptor.invoke(persistenceexceptiontranslationinterceptor.java:155) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.data.jpa.repository.support.lockmoderepositorypostprocessor$lockmodepopulatingmethodintercceptor.invoke(lockmoderepositorypostprocessor.java:91) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.interceptor.exposeinvocationinterceptor.invoke(exposeinvocationinterceptor.java:90) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:202) @ $proxy111.getbuyswithbrandsurveyads(unknown source) @ mycomp.service.brandsurveyservice.getallbuydata(brandsurveyservice.java:66) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.aop.support.aoputils.invokejoinpointusingreflection(aoputils.java:319) @ org.springframework.aop.framework.reflectivemethodinvocation.invokejoinpoint(reflectivemethodinvocation.java:183) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:150) @ org.springframework.security.access.intercept.aopalliance.methodsecurityinterceptor.invoke(methodsecurityinterceptor.java:64) @ org.springframework.aop.framework.reflectivemethodinvocation.proceed(reflectivemethodinvocation.java:172) @ org.springframework.aop.framework.jdkdynamicaopproxy.invoke(jdkdynamicaopproxy.java:202) @ $proxy231.getallbuydata(unknown source) @ mycomp.rest.brandsurveycontroller.getallbuydata(brandsurveycontroller.java:23) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(unknown source) @ sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source) @ java.lang.reflect.method.invoke(unknown source) @ org.springframework.web.method.support.invocablehandlermethod.invoke(invocablehandlermethod.java:219) @ org.springframework.web.method.support.invocablehandlermethod.invokeforrequest(invocablehandlermethod.java:132) @ org.springframework.web.servlet.mvc.method.annotation.servletinvocablehandlermethod.invokeandhandle(servletinvocablehandlermethod.java:100) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.invokehandlermethod(requestmappinghandleradapter.java:604) @ org.springframework.web.servlet.mvc.method.annotation.requestmappinghandleradapter.handleinternal(requestmappinghandleradapter.java:565) @ org.springframework.web.servlet.mvc.method.abstracthandlermethodadapter.handle(abstracthandlermethodadapter.java:80) @ org.springframework.web.servlet.dispatcherservlet.dodispatch(dispatcherservlet.java:923) @ org.springframework.web.servlet.dispatcherservlet.doservice(dispatcherservlet.java:852) @ org.springframework.web.servlet.frameworkservlet.processrequest(frameworkservlet.java:882) @ org.springframework.web.servlet.frameworkservlet.doget(frameworkservlet.java:778) @ javax.servlet.http.httpservlet.service(httpservlet.java:617) @ javax.servlet.http.httpservlet.service(httpservlet.java:717) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:290) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:330) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.invoke(filtersecurityinterceptor.java:118) @ org.springframework.security.web.access.intercept.filtersecurityinterceptor.dofilter(filtersecurityinterceptor.java:84) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.access.exceptiontranslationfilter.dofilter(exceptiontranslationfilter.java:113) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.session.sessionmanagementfilter.dofilter(sessionmanagementfilter.java:103) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.anonymousauthenticationfilter.dofilter(anonymousauthenticationfilter.java:113) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.servletapi.securitycontextholderawarerequestfilter.dofilter(securitycontextholderawarerequestfilter.java:54) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.savedrequest.requestcacheawarefilter.dofilter(requestcacheawarefilter.java:45) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.www.basicauthenticationfilter.dofilter(basicauthenticationfilter.java:150) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:183) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.logout.logoutfilter.dofilter(logoutfilter.java:105) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.authentication.abstractauthenticationprocessingfilter.dofilter(abstractauthenticationprocessingfilter.java:183) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.context.securitycontextpersistencefilter.dofilter(securitycontextpersistencefilter.java:87) @ org.springframework.security.web.filterchainproxy$virtualfilterchain.dofilter(filterchainproxy.java:342) @ org.springframework.security.web.filterchainproxy.dofilterinternal(filterchainproxy.java:192) @ org.springframework.security.web.filterchainproxy.dofilter(filterchainproxy.java:160) @ org.springframework.web.filter.delegatingfilterproxy.invokedelegate(delegatingfilterproxy.java:346) @ org.springframework.web.filter.delegatingfilterproxy.dofilter(delegatingfilterproxy.java:259) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.orm.jpa.support.openentitymanagerinviewfilter.dofilterinternal(openentitymanagerinviewfilter.java:147) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.springframework.web.filter.characterencodingfilter.dofilterinternal(characterencodingfilter.java:88) @ org.springframework.web.filter.onceperrequestfilter.dofilter(onceperrequestfilter.java:76) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ mycomp.nonspringfilters.requestwrapperfilter.dofilter(requestwrapperfilter.java:27) @ org.apache.catalina.core.applicationfilterchain.internaldofilter(applicationfilterchain.java:235) @ org.apache.catalina.core.applicationfilterchain.dofilter(applicationfilterchain.java:206) @ org.apache.catalina.core.standardwrappervalve.invoke(standardwrappervalve.java:233) @ org.apache.catalina.core.standardcontextvalve.invoke(standardcontextvalve.java:191) @ org.apache.catalina.core.standardhostvalve.invoke(standardhostvalve.java:127) @ org.apache.catalina.valves.errorreportvalve.invoke(errorreportvalve.java:103) @ org.apache.catalina.core.standardenginevalve.invoke(standardenginevalve.java:109) @ org.apache.catalina.connector.coyoteadapter.service(coyoteadapter.java:293) @ org.apache.coyote.http11.http11processor.process(http11processor.java:861) @ org.apache.coyote.http11.http11protocol$http11connectionhandler.process(http11protocol.java:606) @ org.apache.tomcat.util.net.jioendpoint$worker.run(jioendpoint.java:489) @ java.lang.thread.run(unknown source) warn: 2013-05-02 14:36:51,860 [http-8080-3] hqlparser.processequalityexpression(259) | hhh000203: processequalityexpression() : no expression process!
i using querydsl 2.9
in example treat 7 parameter template
dateexpression<date> enddateplus7 = datetemplate.create(date.class, "date_add({0}, interval {1} day)", buy.enddate, expressions.constant(7));
if want serialize 7 directly jpql snippet write this
dateexpression<date> enddateplus7 = datetemplate.create(date.class, "date_add({0}, interval {1s} day)", buy.enddate, expressions.constant(7));
since querydsl 3.0 constants automatically wrapped, becomes
dateexpression<date> enddateplus7 = datetemplate.create(date.class, "date_add({0}, interval {1s} day)", buy.enddate, 7);
Comments
Post a Comment