This issue has been created
 
 
XWiki Platform / cid:jira-generated-image-avatar-b456288e-c398-4984-ba6e-d023ad87ad26 XWIKI-22278 Open

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

 
View issue   ยท   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-a84a12ff-83e0-4d7f-ab17-a9c770b25f7d Simon Urli created this issue on 19/Jun/24 14:19
 
Summary: DefaultQueryParameter should be usable for any variable and not only for like condition
Issue Type: cid:jira-generated-image-avatar-b456288e-c398-4984-ba6e-d023ad87ad26 Improvement
Affects Versions: 15.10.10
Assignee: Unassigned
Components: Query
Created: 19/Jun/24 14:19
Priority: cid:jira-generated-image-static-major-f8e51e7b-f91d-4e6c-bedc-fc261f723774 Major
Reporter: Simon Urli
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.