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

Counting documents using parametrized HQL query fails

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Major
    • 2.2.3, 2.3 M1
    • 2.2.2
    • {Unused} Core
    • None
    • regression
    • Trivial

    Description

      I'm trying to count the documents from a given space. The following code fails:

      {{velocity}}
      $xwiki.countDocuments("where doc.space = ?", ["MySpace"])
      {{/velocity}}
      

      with this exception:

      Caused by: com.xpn.xwiki.XWikiException: Error number 3223 in 3: Exception while searching documents with SQL [select count(distinct doc.fullName) from XWikiDocument as doc where (doc.hidden <> true or doc.hidden is null) and doc.space = ?]
      Wrapped Exception: java.lang.Long cannot be cast to [Ljava.lang.Object;
      	at com.xpn.xwiki.store.XWikiHibernateStore.searchGenericInternal(XWikiHibernateStore.java:2470)
      	at com.xpn.xwiki.store.XWikiHibernateStore.countDocuments(XWikiHibernateStore.java:2401)
      	at com.xpn.xwiki.store.XWikiCacheStore.countDocuments(XWikiCacheStore.java:601)
      	at com.xpn.xwiki.api.XWiki.countDocuments(XWiki.java:599)
      

      The following code works fine:

      {{velocity}}
      $xwiki.countDocuments("where doc.space = 'MySpace")
      {{/velocity}}
      

      but I prefer to inject the HQL parameters in a safe way.

      Attachments

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: