Benjamin M. (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f1862a...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiODMwNjgxZTUw...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-14125?atlOrigin=eyJpIjoiODMwNj...
) HHH-14125 (
https://hibernate.atlassian.net/browse/HHH-14125?atlOrigin=eyJpIjoiODMwNj...
) Selecting EntityCollection fails ("not an entity") (
https://hibernate.atlassian.net/browse/HHH-14125?atlOrigin=eyJpIjoiODMwNj...
)
Change By: Benjamin M. (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5f1862a...
)
Selecting an @ElementCollection property via JPQL fails with an exception:
{code:sql}SELECT u.permissions FROM User u WHERE u.id = ?1{code}
throws: {{org.hibernate.QueryException: not an entity}}
Selecting a basic type or associated entity this way works as expected. Adding an explicit
join fixes this:
{ noformat code:sql }SELECT p FROM User u JOIN u.permissions p WHERE u.id = ?1{ noformat
code }
This *works*. The explicit JOIN is *not* needed for basic types and associated entities.
I've attached a test case using the Github hibernate/hibernate-test-case-templates,
because I had some Gradle error when trying to build hibernate-orm directly. Which is a
pitty, bc. I think this test could just be added to the existing [ElementCollection
QueryTest|https://github.com/hibernate/hibernate-orm/blob/5.4.19/hibernat...]
using the existing 'EntityWithAnElementCollection.class'.
Here is the complete Stack Trace for the test case:
{noformat}java.lang.IllegalArgumentException: org.hibernate.QueryException: not an entity
[SELECT u.permissions FROM org.hibernate.bugs.SelectEntityCollectionTestCase$User u WHERE
u.id = ?1]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:138)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:188)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:713)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:729)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:103)
at
org.hibernate.bugs.SelectEntityCollectionTestCase.hhh14125Test(SelectEntityCollectionTestCase.java:93)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at
java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at
org.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at
org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:298)
at
org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:292)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: org.hibernate.QueryException: not an entity [SELECT u.permissions FROM
org.hibernate.bugs.SelectEntityCollectionTestCase$User u WHERE u.id = ?1]
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:220)
at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:118)
at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:78)
at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:158)
at
org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:595)
at
org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:704)
... 18 more
Caused by: org.hibernate.QueryException: not an entity
at
org.hibernate.hql.internal.ast.tree.FromElementType.renderIdentifierSelect(FromElementType.java:174)
at
org.hibernate.hql.internal.ast.tree.FromElement.renderIdentifierSelect(FromElement.java:208)
at
org.hibernate.hql.internal.ast.tree.SelectClause.renderNonScalarIdentifiers(SelectClause.java:464)
at
org.hibernate.hql.internal.ast.tree.SelectClause.renderNonScalarSelects(SelectClause.java:424)
at
org.hibernate.hql.internal.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:247)
at org.hibernate.hql.internal.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:1018)
at org.hibernate.hql.internal.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:786)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:677)
at
org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:313)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:261)
at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:272)
at
org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:192)
... 24 more
{noformat}
(
https://hibernate.atlassian.net/browse/HHH-14125#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-14125#add-comment?atlOrigin=ey...
)
Get Jira notifications on your phone! Download the Jira Cloud app for Android (
https://play.google.com/store/apps/details?id=com.atlassian.android.jira....
) or iOS (
https://itunes.apple.com/app/apple-store/id1006972087?pt=696495&ct=Em...
) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100140- sha1:42b370d )