Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-8719

Count filter doesn't work if the query statement starts with whitespace

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 4.4.1
    • 4.4
    • Query
    • None
    • Unit
    • Easy
    • N/A
    • N/A

    Description

      The following code:

      {{velocity}}
      #set($query = $services.query.xwql('from doc.object(Space.MyClass) as obj'))
      $query.addFilter('count').execute()
      {{/velocity}}
      

      throws:

      Caused by: org.apache.velocity.exception.MethodInvocationException: Invocation of method 'execute' in  class org.xwiki.query.internal.ScriptQuery threw exception org.xwiki.query.QueryException: Exception while execute query. Query statement = [ select doc.fullName from XWikiDocument as doc , BaseObject as obj WHERE 1=1  and doc.fullName=obj.name and obj.className='Space.MyClass' ] at xwiki:Sandbox.FF[line 2, column 27]
      	at org.apache.velocity.runtime.parser.node.ASTMethod.handleInvocationException(ASTMethod.java:243)
      	at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:187)
      	at org.apache.velocity.runtime.parser.node.ASTReference.execute(ASTReference.java:280)
      	at org.apache.velocity.runtime.parser.node.ASTReference.render(ASTReference.java:369)
      	at org.apache.velocity.runtime.parser.node.SimpleNode.render(SimpleNode.java:342)
      	at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:228)
      	... 112 more
      Caused by: org.xwiki.query.QueryException: Exception while execute query. Query statement = [ select doc.fullName from XWikiDocument as doc , BaseObject as obj WHERE 1=1  and doc.fullName=obj.name and obj.className='Space.MyClass' ]
      	at com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor.execute(HqlQueryExecutor.java:115)
      	at org.xwiki.query.internal.DefaultQueryExecutorManager.execute(DefaultQueryExecutorManager.java:68)
      	at org.xwiki.query.internal.DefaultQuery.execute(DefaultQuery.java:248)
      	at org.xwiki.query.xwql.internal.XWQLQueryExecutor.execute(XWQLQueryExecutor.java:97)
      	at org.xwiki.query.internal.DefaultQueryExecutorManager.execute(DefaultQueryExecutorManager.java:68)
      	at org.xwiki.query.internal.SecureQueryExecutorManager.execute(SecureQueryExecutorManager.java:90)
      	at org.xwiki.query.internal.DefaultQuery.execute(DefaultQuery.java:248)
      	at org.xwiki.query.internal.ScriptQuery.execute(ScriptQuery.java:236)
      	at sun.reflect.GeneratedMethodAccessor310.invoke(Unknown Source)
      	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      	at java.lang.reflect.Method.invoke(Method.java:601)
      	at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.doInvoke(UberspectImpl.java:395)
      	at org.apache.velocity.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:384)
      	at org.apache.velocity.runtime.parser.node.ASTMethod.execute(ASTMethod.java:173)
      	... 116 more
      Caused by: com.xpn.xwiki.XWikiException: Error number 0 in 3: Exception while hibernate execute
      Wrapped Exception: unexpected token: rom near line 1, column 28 [select count(doc.fullName) rom XWikiDocument as doc , BaseObject as obj WHERE 1=1  and doc.fullName=obj.name and obj.className='Space.MyClass']
      	at com.xpn.xwiki.store.XWikiHibernateBaseStore.execute(XWikiHibernateBaseStore.java:1227)
      	at com.xpn.xwiki.store.XWikiHibernateBaseStore.executeRead(XWikiHibernateBaseStore.java:1288)
      	at com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor.execute(HqlQueryExecutor.java:96)
      	... 129 more
      Caused by: org.hibernate.hql.ast.QuerySyntaxException: unexpected token: rom near line 1, column 28 [select count(doc.fullName) rom XWikiDocument as doc , BaseObject as obj WHERE 1=1  and doc.fullName=obj.name and obj.className='Space.MyClass']
      	at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
      	at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
      	at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:82)
      	at org.hibernate.hql.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:286)
      	at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:184)
      	at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
      	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
      	at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
      	at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
      	at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
      	at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
      	at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
      	at com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor.createHibernateQuery(HqlQueryExecutor.java:162)
      	at com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor$1.doInHibernate(HqlQueryExecutor.java:102)
      	at com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor$1.doInHibernate(HqlQueryExecutor.java:97)
      	at com.xpn.xwiki.store.XWikiHibernateBaseStore.execute(XWikiHibernateBaseStore.java:1221)
      	... 131 more
      

      The issue is that the query statement (after converting XWQL to HQL) starts with whitespace and this messes up the count filter.

      Attachments

        Activity

          People

            mflorea Marius Dumitru Florea
            mflorea Marius Dumitru Florea
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: