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

DefaultQueryParameter should be usable for any variable and not only for like condition

    XMLWordPrintable

Details

    • Improvement
    • Resolution: Unresolved
    • Major
    • None
    • 15.10.10
    • Query
    • None
    • Unknown

    Description

      It just happened to me that in a query containing nfp.wiki <> :wikiId I tried to use myQuery.bindValue("wikiId").literal("someValue").query().execute() which resulted in the following stacktrace:

      Caused by: java.lang.ClassCastException: class org.xwiki.query.internal.DefaultQueryParameter cannot be cast to class java.lang.String (org.xwiki.query.internal.DefaultQueryParameter is in unnamed module of loader org.eclipse.jetty.webapp.WebAppClassLoader @4a83a74a; java.lang.String is in module java.base of loader 'bootstrap')
      	at org.hibernate.type.descriptor.java.StringTypeDescriptor.unwrap(StringTypeDescriptor.java:22)
      	at org.hibernate.type.descriptor.sql.VarcharTypeDescriptor$1.doBind(VarcharTypeDescriptor.java:46)
      	at org.hibernate.type.descriptor.sql.BasicBinder.bind(BasicBinder.java:73)
      	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:276)
      	at org.hibernate.type.AbstractStandardBasicType.nullSafeSet(AbstractStandardBasicType.java:271)
      	at org.hibernate.param.NamedParameterSpecification.bind(NamedParameterSpecification.java:53)
      	at org.hibernate.loader.hql.QueryLoader.bindParameterValues(QueryLoader.java:682)
      	at org.hibernate.loader.Loader.bindPreparedStatement(Loader.java:2150)
      	at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:2127)
      	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2059)
      	at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:2037)
      	at org.hibernate.loader.Loader.doQuery(Loader.java:956)
      	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:357)
      	at org.hibernate.loader.Loader.doList(Loader.java:2868)
      	at org.hibernate.loader.Loader.doList(Loader.java:2850)
      	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2682)
      	at org.hibernate.loader.Loader.list(Loader.java:2677)
      	at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:540)
      	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:400)
      	at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:218)
      	at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1459)
      	at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1649)
      	at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1617)
      	at com.xpn.xwiki.store.hibernate.query.HqlQueryExecutor.lambda$execute$0(HqlQueryExecutor.java:171)
      	at com.xpn.xwiki.store.XWikiHibernateBaseStore.execute(XWikiHibernateBaseStore.java:826)
      

      After investigating a bit it appeared that DefaultQueryParameter can only be used for variables in like assertions, which is not documented in the javadoc of bindValue.
      IMO it would make sense to allow the support of it anywhere, so that we can use same API in other conditions.

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              surli Simon Urli
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated: