Francisco Sousa (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e949f3...
) *updated* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNjZkOGM2MjU5...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16070?atlOrigin=eyJpIjoiNjZkOG...
) HHH-16070 (
https://hibernate.atlassian.net/browse/HHH-16070?atlOrigin=eyJpIjoiNjZkOG...
) Exception when find by association id that is a generic @EmbeddedId with
@MappedSuperclass (
https://hibernate.atlassian.net/browse/HHH-16070?atlOrigin=eyJpIjoiNjZkOG...
)
Change By: Francisco Sousa (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e949f3...
)
I have the following abstracts base classes:
{code:java}@MappedSuperclass
public abstract class DomainEntityId implements Serializable {
private final Long value;
protected DomainEntityId() {
this.value = RandomGenerator.getDefault().nextLong();
}
public Long getValue() {
return value;
}
}{code}
{code:java}@MappedSuperclass
public abstract class DomainEntityModel<ID extends DomainEntityId> {
@EmbeddedId
@AttributeOverride(name = "value", column = @Column(name = "id"))
private final ID id;
protected DomainEntityModel(ID id) {
this.id = id;
}
@NonNull
public ID getId() {
return id;
}
}{code}
and the following concrete entities:
{code:java}@Embeddable
public class CustomerId extends DomainEntityId {}{code}
{noformat}@Entity
public class Customer extends DomainEntityModel<CustomerId> {
private Integer code;
private String name;
public Customer() {
super(new CustomerId());
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}{noformat}
{noformat}@Embeddable
public class InvoiceId extends DomainEntityId {}{noformat}
{noformat}@Entity
public class Invoice extends DomainEntityModel<InvoiceId> {
private Integer number;
@ManyToOne
private Customer customer;
public Invoice() {
super(new InvoiceId());
}
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
}{noformat}
When I try to find invoices by customer id, I get the following exception:
{noformat}java.lang.IllegalArgumentException: Argument [ br org. com hibernate.
leverinfo.mappedsuperclassissue. model.CustomerId@ 3c2c9b59 311a0b3e ] of type [ br org.
com hibernate. leverinfo.mappedsuperclassissue. model.CustomerId] did not match parameter
type [ br org. com hibernate. leverinfo.mappedsuperclassissue. model.InvoiceId (n/a)]
at
org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:84)
~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at
org.hibernate.query.spi.QueryParameterBindingValidator.validate(QueryParameterBindingValidator.java:31)
~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at
org.hibernate.query.internal.QueryParameterBindingImpl.validate(QueryParameterBindingImpl.java:339)
~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at
org.hibernate.query.internal.QueryParameterBindingImpl.setBindValue(QueryParameterBindingImpl.java:129)
~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at
org.hibernate.query.spi.AbstractCommonQueryContract.setParameter(AbstractCommonQueryContract.java:
1066 860 ) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at
org.hibernate.query.spi.AbstractSelectionQuery.setParameter(AbstractSelectionQuery.java:
774 708 ) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org.hibernate.query.sqm.internal.QuerySqmImpl.setParameter(QuerySqmImpl.java: 1329 1263
) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org.hibernate.query.sqm.internal.QuerySqmImpl.setParameter(QuerySqmImpl.java:131)
~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org. springframework hibernate. data bugs. jpa JPAUnitTestCase.
repository.query.QueryParameterSetter$BindableQuery.setParameter findByAssociationIdTest (
QueryParameterSetter JPAUnitTestCase.java: 314 47 ) ~[spring-data-jpa-3
at java. 0 base/jdk. 0 internal. jar:3 reflect. 0 NativeMethodAccessorImpl. 0]
invoke0(Native Method)
at org java. springframework base/jdk. data internal. jpa reflect. repository
NativeMethodAccessorImpl.
query.QueryParameterSetter$NamedOrIndexedQueryParameterSetter.lambda$setParameter$3 invoke
( QueryParameterSetter NativeMethodAccessorImpl.java: 111 62 )
~[spring-data-jpa-3.0.0.jar:3.0.0]
at org java. springframework base/jdk. data internal. jpa reflect. repository
DelegatingMethodAccessorImpl. query.QueryParameterSetter$ErrorHandling$1.execute invoke (
QueryParameterSetter DelegatingMethodAccessorImpl.java: 136 43 )
~[spring-data-jpa-3.0.0.jar:3.0.0]
at org java. springframework base/java. data lang. jpa reflect. repository Method.
query.QueryParameterSetter$NamedOrIndexedQueryParameterSetter.setParameter invoke (
QueryParameterSetter Method.java: 111 566 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. jpa model. repository FrameworkMethod$1.
query.ParameterBinder.bind runReflectiveCall ( ParameterBinder FrameworkMethod.java: 83 59
) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data internal. jpa runners. repository model. query
ReflectiveCallable. ParameterBinder.bind run ( ParameterBinder ReflectiveCallable.java: 75
12 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. jpa model. repository FrameworkMethod.
query.ParameterBinder.bindAndPrepare invokeExplosively ( ParameterBinder
FrameworkMethod.java: 97 56 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data internal. jpa runners. repository statements. query
InvokeMethod. PartTreeJpaQuery$QueryPreparer.invokeBinding evaluate ( PartTreeJpaQuery
InvokeMethod.java: 312 17 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data internal. jpa runners. repository statements. query
RunBefores. PartTreeJpaQuery$QueryPreparer.createQuery evaluate ( PartTreeJpaQuery
RunBefores.java: 231 26 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data internal. jpa runners. repository statements. query
RunAfters. PartTreeJpaQuery.doCreateQuery evaluate ( PartTreeJpaQuery RunAfters.java: 102
27 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. jpa ParentRunner$3.
repository.query.AbstractJpaQuery.createQuery evaluate ( AbstractJpaQuery
ParentRunner.java: 234 306 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. jpa.repository.query.JpaQueryExecution
BlockJUnit4ClassRunner $ CollectionExecution 1. doExecute evaluate ( JpaQueryExecution
BlockJUnit4ClassRunner.java: 127 100 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. jpa ParentRunner.
repository.query.JpaQueryExecution.execute runLeaf ( JpaQueryExecution ParentRunner.java:
90 366 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. jpa BlockJUnit4ClassRunner.
repository.query.AbstractJpaQuery.doExecute runChild ( AbstractJpaQuery
BlockJUnit4ClassRunner.java: 148 103 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. jpa BlockJUnit4ClassRunner.
repository.query.AbstractJpaQuery.execute runChild ( AbstractJpaQuery
BlockJUnit4ClassRunner.java: 136 63 ) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. repository ParentRunner$4.
core.support.RepositoryMethodInvoker.doInvoke run ( RepositoryMethodInvoker
ParentRunner.java: 136 331 ) ~[spring-data-commons-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. repository ParentRunner$1.
core.support.RepositoryMethodInvoker.invoke schedule ( RepositoryMethodInvoker
ParentRunner.java: 120 79 ) ~[spring-data-commons-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. repository ParentRunner.
core.support.QueryExecutorMethodInterceptor.doInvoke runChildren (
QueryExecutorMethodInterceptor ParentRunner.java: 164 329 )
~[spring-data-commons-3.0.0.jar:3.0.0]
at org. springframework junit. data runners. repository ParentRunner.
core.support.QueryExecutorMethodInterceptor.invoke access$100 (
QueryExecutorMethodInterceptor ParentRunner.java: 143 66 )
~[spring-data-commons-3.0.0.jar:3.0.0]
at org. springframework junit. aop runners. framework ParentRunner$2.
ReflectiveMethodInvocation.proceed evaluate ( ReflectiveMethodInvocation
ParentRunner.java: 184 293 ) ~[spring-aop-6.0.3.jar:6.0.3]
at org. springframework junit. data runners. projection ParentRunner$3.
DefaultMethodInvokingMethodInterceptor.invoke evaluate (
DefaultMethodInvokingMethodInterceptor ParentRunner.java: 77 306 )
~[spring-data-commons-3.0.0.jar:3.0.0]
at org. springframework junit. aop runners. framework ParentRunner.
ReflectiveMethodInvocation.proceed run ( ReflectiveMethodInvocation ParentRunner.java: 184
413 ) ~[spring-aop-6.0.3.jar:6.0.3]
at org. springframework junit. transaction runner. interceptor JUnitCore.
TransactionInterceptor$1.proceedWithInvocation run ( TransactionInterceptor
JUnitCore.java: 123 137 ) ~[spring-tx-6.0.3.jar:6.0.3]
at org com. springframework intellij. transaction junit4. interceptor
JUnit4IdeaTestRunner. TransactionAspectSupport.invokeWithinTransaction startRunnerWithArgs
( TransactionAspectSupport JUnit4IdeaTestRunner.java: 388 69 )
~[spring-tx-6.0.3.jar:6.0.3]
at org com. springframework intellij. transaction rt. interceptor junit.
TransactionInterceptor IdeaTestRunner$Repeater$1. invoke execute ( TransactionInterceptor
IdeaTestRunner.java: 119 38 ) ~[spring-tx-6.0.3.jar:6.0.3]
at org com. springframework intellij. aop rt. framework execution.
ReflectiveMethodInvocation junit. proceed TestsRepeater.repeat (
ReflectiveMethodInvocation TestsRepeater.java: 184 11 ) ~[spring-aop-6.0.3.jar:6.0.3]
at org com. springframework intellij. dao rt. support junit.
PersistenceExceptionTranslationInterceptor IdeaTestRunner$Repeater. invoke
startRunnerWithArgs ( PersistenceExceptionTranslationInterceptor IdeaTestRunner.java: 137
35 ) ~[spring-tx-6.0.3.jar:6.0.3]
at org com. springframework intellij. aop rt. framework junit. ReflectiveMethodInvocation
JUnitStarter. proceed prepareStreamsAndStart ( ReflectiveMethodInvocation
JUnitStarter.java: 184 235 ) ~[spring-aop-6.0.3.jar:6.0.3]
at org com. springframework intellij. data rt. jpa junit. repository JUnitStarter.
support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke
main ( CrudMethodMetadataPostProcessor JUnitStarter.java: 134 54 )
~[spring-data-jpa-3.0.0.jar:3.0.0]
... {noformat}
I’ve debug as I could and AFAICS, as both concrete entities share the same superclass,
there is only one
[
MappedSuperclass|https://docs.jboss.org/hibernate/orm/6.1/javadocs/org/hi...]
instance and the {{DeclaredIdentifierProperty}} is being replaced with the id of the last
entity. After, this id is used to validate the query parameter value and they are
incompatibles.
There is a similar problem
[
https://hibernate.atlassian.net/browse/HHH-11955|https://hibernate.atlass...],
although I’m not sure that is exactly the same.
In Here is a test case demonstrating this repository issue in Hibernate 6
[
https://github.com/franciscosousabr/ mappedsuperclassissue
test-case-template-hibernate-orm6 |https://github.com/franciscosousabr/
mappedsuperclassissue test-case-template-hibernate-orm6 |smart-link] I have an example of
this issue.
In branch {{master}} the error and here is occurring.
In branch {{hibernate-5}}, a test case demonstrating the same code works well working in
Hibernate 5 [
https://github.
com/franciscosousabr/test-case-template-hibernate-orm5|https://github.com...]
(
https://hibernate.atlassian.net/browse/HHH-16070#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16070#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#100214- sha1:fa7bc5f )