This issue has been created
There are 2 updates.
 
 
XWiki Platform / cid:jira-generated-image-avatar-5f2448aa-b1a2-4f0b-b0e1-9a9e12aea63b XWIKI-22621 Open

XWQL subqueries (IN and NOT IN operators) don't seem translated to HQL

 
View issue   ·   Add comment
 

Issue created

 
cid:jira-generated-image-avatar-e31db2d6-93c9-4229-b2f7-2759790f1668 Raphaël Jakse created this issue on 30/Oct/24 16:00
 
Summary: XWQL subqueries (IN and NOT IN operators) don't seem translated to HQL
Issue Type: cid:jira-generated-image-avatar-5f2448aa-b1a2-4f0b-b0e1-9a9e12aea63b Bug
Affects Versions: 16.6.0
Assignee: Unassigned
Components: Query
Created: 30/Oct/24 16:00
Priority: cid:jira-generated-image-static-major-f4d5ecc4-1053-4a99-9c36-8e0f07f3c4da Major
Reporter: Raphaël Jakse
Description:

I tried:

{{groovy}}
services.query.xwql("select space.reference from Space space where space.reference not in (select d.fullName from Document d)").execute()
{{/groovy}}

I expected the query to run fine (I guess I'm supposed to get a list of spaces without a corresponding document; this is a MWE, this may not actually be accurate or even useful).

Instead, I got:

Failed to execute the [groovy] macro. Cause: [Document is not mapped]. Click on this message for details.

The relevant stack trace:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Document is not mapped [ select space.reference from com.xpn.xwiki.doc.XWikiSpace as space where space.reference not in ( select d.fullName from Document d ) ]
 at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
 at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:220)
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
 at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:112)
 at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
 at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162)
 at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:636)
 at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:748)
 ... 225 more
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Document is not mapped
 at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:170)
 at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
 at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:77)
 at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:334)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3782)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3671)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:746)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:602)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:5020)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4919)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4602)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2180)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:841)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:635)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:339)
 at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:287)
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:276)
 at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192)
 ... 231 more

More precisely, the query seems to be translated to the following HQL:

select space.reference from com.xpn.xwiki.doc.XWikiSpace as space where space.reference not in ( select d.fullName from Document d )

what is between the NOT IN parentheses is surprising, Document should have been translated to XWIkiDocument. This part of the query seems to be output as is instead of translated.

 
 

2 updates

 
cid:jira-generated-image-avatar-e31db2d6-93c9-4229-b2f7-2759790f1668 Changes by Raphaël Jakse on 30/Oct/24 16:01
 
Description: I tried:
{code:java}
{{groovy}}
services.query.xwql("select space.reference from Space space where space.reference not in (select d.fullName from Document d)").execute()
{{/groovy}}
{code}
I expected the query to run fine (I guess I'm supposed to get a list of spaces without a corresponding document; this is a MWE, this may not actually be accurate or even useful).

Instead, I got:
{code:java}
Failed to execute the [groovy] macro. Cause: [Document is not mapped]. Click on this message for details.
{code}
The relevant stack trace:
{code:java}
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Document is not mapped [ select space.reference from com.xpn.xwiki.doc.XWikiSpace as space where space.reference not in ( select d.fullName from Document d ) ]
at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:220)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:112)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:73)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:162)
at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:636)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:748)
... 225 more
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: Document is not mapped
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:170)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:77)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:334)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3782)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3671)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:746)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:602)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.collectionFunctionOrSubselect(HqlSqlBaseWalker.java:5020)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.inRhs(HqlSqlBaseWalker.java:4919)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4602)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2180)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:841)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:635)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:339)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:287)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:276)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192)
... 231 more
{code}
More precisely, the query seems to be translated to the following HQL:
{code:java}
select space.reference from com.xpn.xwiki.doc.XWikiSpace as space where space.reference not in ( select d.fullName from Document d )
{code}
what is between the {{NOT IN}} parentheses is surprising, {{Document}} should have been translated to {{{}
XWIkiDocument XWi {}}} {{{}kiDocument{}}} . This part of the query seems to be output as - is instead of translated.
Assignee: Raphaël Jakse