TREAT in WHERE clause throws exception

Description

Hello,

I have two entities:

@Entity("product") public class Product { }

and

@Entity("variant_product") public class VariantProduct extends Product { }

Now I call the following query:

select p from product p where TREAT(p AS variant_product).baseProduct is null and p.catalogVersion in :catalogVersions

and I get the following exception:

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: i.getText().equals("treat") [select p from com.nemesis.platform.module.commerce.core.entity.catalog.ProductEntity p where TREAT(p AS variant_product).baseProduct is null and p.catalogVersion in :catalogVersions] at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74) at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:288) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:187) at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:115) at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:76) at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:150) at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:302) at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:240) at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1907) at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291) ... 208 more

I marked it as critical because I think this breaks the JPA specification.

Activity

Christian BeikovApril 8, 2022 at 12:15 PM

Since no test case was provided for years, I'll close this issue as out of date. I also believe it will most probably not be an issue any more in 6.0.
If this still is an issue for you, please create a new issue with a test case that reproduces the problem.

Christian BeikovJuly 26, 2016 at 6:15 AM

I think this is a duplicate of HHH-9345. The actual problem is that the grammar does not allow an identification variable, but only paths in the treat.

Out of Date

Details

Assignee

Reporter

Priority

Created July 24, 2016 at 7:13 AM
Updated April 8, 2022 at 12:15 PM
Resolved April 8, 2022 at 12:15 PM

Flag notifications