Hi everyone.
What is the right way to use boolean constants in HQL?
Consider the following query:
Code:
from MyEntity myEntity where myEntity.name = 'name' and true
It is correct according to the AST grammar. However, Hibernate throws an error.
The following query works but it's not nice:
Code:
from MyEntity myEntity where myEntity.name = 'name' and 1 = 1
This is a minor point but I just wonder if I miss something.
Hibernate version: 3.2.2.ga
Full stack trace of any exception that occurs:
org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: true near line 1, column 364 [select distinct irecord.id as id from de.disy.preludio2.nokis.record.model.impl.NokisMetadataRecord as irecord where irecord.recordType.name = 'nokisMetadata' and irecord.removed = false and true]
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:235)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:160)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:111)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:77)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:56)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:72)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:133)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:112)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1623)
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:585)
at org.springframework.orm.hibernate3.HibernateTemplate$CloseSuppressingInvocationHandler.invoke(HibernateTemplate.java:1197)
at $Proxy16.createQuery(Unknown Source)
at de.disy.commons.hibernate.hql.QueryRule.createQuery(QueryRule.java:228)
at de.disy.commons.hibernate.hql.QueryRule.list(QueryRule.java:263)
at de.disy.commons.hibernate.hql.QueryRule$1.doInHibernate(QueryRule.java:314)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:367)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:333)
at de.disy.commons.hibernate.hql.QueryRule.list(QueryRule.java:310)
at de.disy.preludio2.query.processor.hibernate.AbstractHQLQueryProcessor$HQLRecordDescriptionLister.getRecordDescriptions(AbstractHQLQueryProcessor.java:105)
at de.disy.preludio2.ws.service.csw.impl.AbstractSearchResultsService.createSearchResults(AbstractSearchResultsService.java:36)
at de.disy.preludio2.ws.service.csw.impl.DefaultGetRecordsService.createSearchResults(DefaultGetRecordsService.java:166)
at de.disy.preludio2.ws.service.csw.impl.DefaultGetRecordsService.executeResults(DefaultGetRecordsService.java:149)
at de.disy.preludio2.ws.service.csw.impl.DefaultGetRecordsService.execute(DefaultGetRecordsService.java:83)
at de.disy.preludio2.ws.service.csw.impl.DefaultGetRecordsService.execute(DefaultGetRecordsService.java:1)
at de.disy.preludio2.ws.service.impl.ServiceEndpoint.invokeInternal(ServiceEndpoint.java:23)
at org.springframework.ws.server.endpoint.AbstractMarshallingPayloadEndpoint.invoke(AbstractMarshallingPayloadEndpoint.java:91)
at org.springframework.ws.server.endpoint.MessageEndpointAdapter.invoke(MessageEndpointAdapter.java:35)
at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:205)
at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:166)
at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handle(WebServiceMessageReceiverObjectSupport.java:78)
at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:60)
at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:125)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:399)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:364)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:491)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1074)
at teamdev.jsf.util.ResourceFilter.doFilter(SourceFile:67)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1065)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:365)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:185)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:689)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:391)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:285)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:457)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:765)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:628)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:209)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:357)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:329)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:475)