[JIRA] (HHH-16188) Exception when find by field of generic @EmbeddedId with @MappedSuperclass
by Rok Marinsek (JIRA)
Rok Marinsek ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63ee251... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiOWVmMzg2MGYz... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16188?atlOrigin=eyJpIjoiOWVmMz... ) HHH-16188 ( https://hibernate.atlassian.net/browse/HHH-16188?atlOrigin=eyJpIjoiOWVmMz... ) Exception when find by field of generic @EmbeddedId with @MappedSuperclass ( https://hibernate.atlassian.net/browse/HHH-16188?atlOrigin=eyJpIjoiOWVmMz... )
Change By: Rok Marinsek ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=63ee251... )
We have the following abstract base classes:
{code:java}@Embeddable
@MappedSuperclass
public abstract class DomainEntityId implements Serializable {
private final Long domainId;
protected DomainEntityId() {
Random random = new Random();
this.domainId = random.nextLong();
}
...
}{code}
{ noformat code:java }@MappedSuperclass
public abstract class DomainEntityModel<ID extends DomainEntityId> {
@EmbeddedId
@NonNull
private ID id;
protected DomainEntityModel(ID id) {
this.id = id;
}
...
}{ noformat code }
and the concrete class:
{code:java}@Entity
public class Customer extends DomainEntityModel<Customer.CustomerId> {
private Integer code;
private String name;
@Embeddable
public static class CustomerId extends DomainEntityId {
private int someDomainField;
public CustomerId() {
super();
this.someDomainField = new Random().nextInt();
}
public int getSomeDomainField() {
return someDomainField;
}
}
public Customer(Integer code, String name) {
this();
this.code = code;
this.name = name;
}
protected Customer() {
super(new CustomerId());
}
...
}{code}
When we try to find a customer by someDomainField, we get the following exception:
{noformat}java.lang.IllegalArgumentException: org.hibernate.query.sqm.InterpretationException: Error interpreting query [from Customer c where c.id.someDomainField = :someDomainField]; this may indicate a semantic (user query) problem or a bug in the parser [from Customer c where c.id.someDomainField = :someDomainField]
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:141)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:175)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:182)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:760)
at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:187)
at org.hibernate.bugs.JPAUnitTestCase.findByDomainIdFieldTest(JPAUnitTestCase.java:40)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
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.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
at com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
at com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: org.hibernate.query.sqm.InterpretationException: Error interpreting query [from Customer c where c.id.someDomainField = :someDomainField]; this may indicate a semantic (user query) problem or a bug in the parser [from Customer c where c.id.someDomainField = :someDomainField]
at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:97)
at org.hibernate.internal.AbstractSharedSessionContract.lambda$createQuery$2(AbstractSharedSessionContract.java:747)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.createHqlInterpretation(QueryInterpretationCacheStandardImpl.java:141)
at org.hibernate.query.internal.QueryInterpretationCacheStandardImpl.resolveHqlInterpretation(QueryInterpretationCacheStandardImpl.java:128)
at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:744)
... 31 more
Caused by: java.lang.IllegalArgumentException: org.hibernate.query.SemanticException: Could not resolve attribute 'someDomainField' of 'org.hibernate.model.DomainEntityId'
at org.hibernate.query.sqm.SqmPathSource.getSubPathSource(SqmPathSource.java:61)
at org.hibernate.query.sqm.tree.domain.AbstractSqmPath.get(AbstractSqmPath.java:162)
at org.hibernate.query.sqm.tree.domain.SqmEmbeddedValuedSimplePath.resolvePathPart(SqmEmbeddedValuedSimplePath.java:75)
at org.hibernate.query.hql.internal.DomainPathPart.resolvePathPart(DomainPathPart.java:42)
at org.hibernate.query.hql.internal.BasicDotIdentifierConsumer.consumeIdentifier(BasicDotIdentifierConsumer.java:91)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSimplePath(SemanticQueryBuilder.java:4819)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitIndexedPathAccessFragment(SemanticQueryBuilder.java:4766)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitGeneralPathFragment(SemanticQueryBuilder.java:4735)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitGeneralPathExpression(SemanticQueryBuilder.java:1423)
at org.hibernate.grammars.hql.HqlParser$GeneralPathExpressionContext.accept(HqlParser.java:6972)
at org.antlr.v4.runtime.tree.AbstractParseTreeVisitor.visitChildren(AbstractParseTreeVisitor.java:46)
at org.hibernate.grammars.hql.HqlParserBaseVisitor.visitBarePrimaryExpression(HqlParserBaseVisitor.java:671)
at org.hibernate.grammars.hql.HqlParser$BarePrimaryExpressionContext.accept(HqlParser.java:6446)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitComparisonPredicate(SemanticQueryBuilder.java:2105)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitComparisonPredicate(SemanticQueryBuilder.java:243)
at org.hibernate.grammars.hql.HqlParser$ComparisonPredicateContext.accept(HqlParser.java:5493)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitWhereClause(SemanticQueryBuilder.java:1949)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitWhereClause(SemanticQueryBuilder.java:243)
at org.hibernate.grammars.hql.HqlParser$WhereClauseContext.accept(HqlParser.java:5292)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuery(SemanticQueryBuilder.java:857)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuerySpecExpression(SemanticQueryBuilder.java:629)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitQuerySpecExpression(SemanticQueryBuilder.java:243)
at org.hibernate.grammars.hql.HqlParser$QuerySpecExpressionContext.accept(HqlParser.java:1220)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSimpleQueryGroup(SemanticQueryBuilder.java:623)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSimpleQueryGroup(SemanticQueryBuilder.java:243)
at org.hibernate.grammars.hql.HqlParser$SimpleQueryGroupContext.accept(HqlParser.java:1133)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitSelectStatement(SemanticQueryBuilder.java:399)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.visitStatement(SemanticQueryBuilder.java:358)
at org.hibernate.query.hql.internal.SemanticQueryBuilder.buildSemanticModel(SemanticQueryBuilder.java:285)
at org.hibernate.query.hql.internal.StandardHqlTranslator.translate(StandardHqlTranslator.java:81)
... 35 more
Caused by: org.hibernate.query.SemanticException: Could not resolve attribute 'someDomainField' of 'org.hibernate.model.DomainEntityId'
... 65 more
{noformat}
Seems to be a similar issue to [https://hibernate.atlassian.net/browse/HHH-16070|https://hibernate.atlass...].
A demonstrating test case for ORM-6: [https://github.com/marok39/hibernate-test-case-orm6-embedded-domain-id|ht...]
and working example for ORM-5: [https://github.com/marok39/hibernate-test-case-orm6-embedded-domain-id/tr...]
( https://hibernate.atlassian.net/browse/HHH-16188#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16188#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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100216- sha1:a0b8fe5 )
1 year, 10 months