Usage of TYPE operator causes "org.hibernate.QueryException: could not resolve property: class of: [entity class]"

Description

In an inheritance hierarchy a mapped superclass causes a query to fail if the `TYPE` operator is used, e.g. `SELECT x from B x WHERE TYPE = B` fails with `org.hibernate.QueryException: could not resolve property: class of: de.richtercloud.type.operator.nonsense.B` (B is a subclass of A, both POJOs) if A is a mapped superclass and only succeeds if A is an entity. This doesn't correspond to the JPA 2.1 `TYPE` operator specification.

A minimal example for the issue can be found at https://github.com/krichter722/type-operator-nonsense at commit f5909c7. The example allows to easily switch to OpenJPA which works fine.

Environment

Apache Derby 10.11.1.1

Activity

Show:
Gail Badner
March 29, 2016, 11:11 PM

Exception in thread "main" java.lang.IllegalArgumentException: org.hibernate.QueryException: could not resolve property: class of: de.richtercloud.type.operator.nonsense.B [SELECT x from de.richtercloud.type.operator.nonsense.B x WHERE TYPE = B]
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1679)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:294)
at de.richtercloud.type.operator.nonsense.NewMain.main(NewMain.java:43)
Caused by: org.hibernate.QueryException: could not resolve property: class of: de.richtercloud.type.operator.nonsense.B [SELECT x from de.richtercloud.type.operator.nonsense.B x WHERE TYPE = B]
at org.hibernate.QueryException.generateQueryException(QueryException.java:120)
at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)
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:1894)
at org.hibernate.jpa.spi.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:291)
... 1 more
Caused by: org.hibernate.QueryException: could not resolve property: class of: de.richtercloud.type.operator.nonsense.B
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:62)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:56)
at org.hibernate.persister.entity.AbstractEntityPersister.getSubclassPropertyTableNumber(AbstractEntityPersister.java:1770)
at org.hibernate.persister.entity.BasicEntityPropertyMapping.toColumns(BasicEntityPropertyMapping.java:46)
at org.hibernate.persister.entity.AbstractEntityPersister.toColumns(AbstractEntityPersister.java:1745)
at org.hibernate.persister.entity.AbstractEntityPersister$3.getSqlFragment(AbstractEntityPersister.java:1822)
at org.hibernate.hql.internal.ast.tree.FromElement$TypeDiscriminatorMetadataImpl.getSqlFragment(FromElement.java:472)
at org.hibernate.hql.internal.ast.tree.MethodNode.typeDiscriminator(MethodNode.java:111)
at org.hibernate.hql.internal.ast.tree.MethodNode.resolve(MethodNode.java:80)
at org.hibernate.hql.internal.ast.HqlSqlWalker.processFunction(HqlSqlWalker.java:1074)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.functionCall(HqlSqlBaseWalker.java:2740)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1358)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4710)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:4180)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2127)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:810)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:605)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:309)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:257)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
... 9 more

Giovanni Lovato
June 6, 2019, 7:26 AM

What's the status of this? Still in 5.4

Assignee

Unassigned

Reporter

KarlR

Fix versions

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure