[JIRA] (HHH-16070) Exception when find by association id that is a generic @EmbeddedId with @MappedSuperclass
by Francisco Sousa (JIRA)
Francisco Sousa ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e949f3... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNmYyMjk2Njgx... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16070?atlOrigin=eyJpIjoiNmYyMj... ) HHH-16070 ( https://hibernate.atlassian.net/browse/HHH-16070?atlOrigin=eyJpIjoiNmYyMj... ) Exception when find by association id that is a generic @EmbeddedId with @MappedSuperclass ( https://hibernate.atlassian.net/browse/HHH-16070?atlOrigin=eyJpIjoiNmYyMj... )
Issue Type: Bug Affects Versions: 6.0.0, 6.0.1, 6.0.2, 6.1.0, 6.1.1, 6.1.2, 6.1.3, 6.1.4, 6.1.5, 6.1.6 Assignee: Unassigned Created: 19/Jan/2023 15:35 PM Priority: Major Reporter: Francisco Sousa ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5e949f3... )
I have the following abstracts base classes:
@MappedSuperclass
public abstract class DomainEntityId implements Serializable {
private final Long value;
protected DomainEntityId() {
this.value = RandomGenerator.getDefault().nextLong();
}
public Long getValue() {
return value;
}
}
@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;
}
}
and the following concrete entities:
@Embeddable
public class CustomerId extends DomainEntityId {}
@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;
}
}
@Embeddable
public class InvoiceId extends DomainEntityId {}
@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;
}
}
When I try to find invoices by customer id, I get the following exception:
java.lang.IllegalArgumentException: Argument [br.com.leverinfo.mappedsuperclassissue.model.CustomerId@3c2c9b59] of type [br.com.leverinfo.mappedsuperclassissue.model.CustomerId] did not match parameter type [br.com.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) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org.hibernate.query.spi.AbstractSelectionQuery.setParameter(AbstractSelectionQuery.java:774) ~[hibernate-core-6.1.6.Final.jar:6.1.6.Final]
at org.hibernate.query.sqm.internal.QuerySqmImpl.setParameter(QuerySqmImpl.java:1329) ~[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.data.jpa.repository.query.QueryParameterSetter$BindableQuery.setParameter(QueryParameterSetter.java:314) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.QueryParameterSetter$NamedOrIndexedQueryParameterSetter.lambda$setParameter$3(QueryParameterSetter.java:111) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.QueryParameterSetter$ErrorHandling$1.execute(QueryParameterSetter.java:136) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.QueryParameterSetter$NamedOrIndexedQueryParameterSetter.setParameter(QueryParameterSetter.java:111) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:83) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.ParameterBinder.bind(ParameterBinder.java:75) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.ParameterBinder.bindAndPrepare(ParameterBinder.java:97) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.invokeBinding(PartTreeJpaQuery.java:312) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery$QueryPreparer.createQuery(PartTreeJpaQuery.java:231) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.doCreateQuery(PartTreeJpaQuery.java:102) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.createQuery(AbstractJpaQuery.java:234) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:127) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:90) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:148) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:136) ~[spring-data-jpa-3.0.0.jar:3.0.0]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.doInvoke(RepositoryMethodInvoker.java:136) ~[spring-data-commons-3.0.0.jar:3.0.0]
at org.springframework.data.repository.core.support.RepositoryMethodInvoker.invoke(RepositoryMethodInvoker.java:120) ~[spring-data-commons-3.0.0.jar:3.0.0]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.doInvoke(QueryExecutorMethodInterceptor.java:164) ~[spring-data-commons-3.0.0.jar:3.0.0]
at org.springframework.data.repository.core.support.QueryExecutorMethodInterceptor.invoke(QueryExecutorMethodInterceptor.java:143) ~[spring-data-commons-3.0.0.jar:3.0.0]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.3.jar:6.0.3]
at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:77) ~[spring-data-commons-3.0.0.jar:3.0.0]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.3.jar:6.0.3]
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-6.0.3.jar:6.0.3]
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-6.0.3.jar:6.0.3]
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-6.0.3.jar:6.0.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.3.jar:6.0.3]
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137) ~[spring-tx-6.0.3.jar:6.0.3]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.0.3.jar:6.0.3]
at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:134) ~[spring-data-jpa-3.0.0.jar:3.0.0]
...
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/hibernate/mapping/M... ) 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.atlassian.net/browse/HHH-11955 ) , although I’m not sure that is exactly the same.
In this repository https://github.com/franciscosousabr/mappedsuperclassissue ( https://github.com/franciscosousabr/mappedsuperclassissue ) I have an example of this issue.
In branch master the error is occurring.
In branch hibernate-5 , the same code works well.
( 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=EmailN... ) This message was sent by Atlassian Jira (v1001.0.0-SNAPSHOT#100214- sha1:5a2a1e8 )
1 year, 8 months
[JIRA] (HHH-16069) Defer handling of custom types until after deployment time
by Scott Marlow (JIRA)
Scott Marlow ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *created* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiMzg1YzAwZGUx... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16069?atlOrigin=eyJpIjoiMzg1Yz... ) HHH-16069 ( https://hibernate.atlassian.net/browse/HHH-16069?atlOrigin=eyJpIjoiMzg1Yz... ) Defer handling of custom types until after deployment time ( https://hibernate.atlassian.net/browse/HHH-16069?atlOrigin=eyJpIjoiMzg1Yz... )
Issue Type: Bug Affects Versions: 6.1.5 Assignee: Unassigned Components: hibernate-core Created: 19/Jan/2023 14:24 PM Fix Versions: 6.2.0 Priority: Major Reporter: Scott Marlow ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
https://groups.google.com/d/msgid/wildfly/ba3a578f-7f42-4fda-8736-9fb95c9... ( https://groups.google.com/d/msgid/wildfly/ba3a578f-7f42-4fda-8736-9fb95c9... ) reported exception “org.hibernate.resource.beans.container.internal.NotYetReadyException: CDI BeanManager not (yet) ready to use" being thrown during the second 2-phase bootstrap deployment which is too early.
Please defer the org.hibernate.mapping.BasicValue.setExplicitCustomType() processing until later.
Paste of the exception from the above linked user report:
“
7:08:49,386 ERROR [org.jboss.msc.service.fail] (ServerService Thread Pool – 80) MSC000001: Failed to start service jboss.persistenceunit."XXX": org.jboss.msc.service.StartException in service jboss.persistenceunit.""XXX": org.hibernate.resource.beans.container.internal.NotYetReadyException: CDI BeanManager not (yet) ready to use
at org.jbos...@27.0.1.Final//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:199)
at org.jbos...@27.0.1.Final//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:129)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
at org.wildfly.secu...@2.0.0.Final//org.wildfly.security.manager.WildFlySecurityManager.doChecked(WildFlySecurityManager.java:664)
at org.jbos...@27.0.1.Final//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1.run(PersistenceUnitServiceImpl.java:214)
at org.jbos...@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:833)
at org.jbos...@2.4.0.Final//org.jboss.threads.JBossThread.run(JBossThread.java:513)
Caused by: org.hibernate.resource.beans.container.internal.NotYetReadyException: CDI BeanManager not (yet) ready to use
at org.hi...@6.1.5.Final//org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy$NamedBeanImpl.initialize(JpaCompliantLifecycleStrategy.java:231)
at org.hi...@6.1.5.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl$NamedBeanImpl.initialize(CdiBeanContainerExtendedAccessImpl.java:165)
at org.hi...@6.1.5.Final//org.hibernate.resource.beans.container.internal.CdiBeanContainerExtendedAccessImpl$NamedBeanImpl.getBeanInstance(CdiBeanContainerExtendedAccessImpl.java:172)
at org.hi...@6.1.5.Final//org.hibernate.resource.beans.internal.ManagedBeanRegistryImpl$ContainedBeanManagedBeanAdapter.getBeanInstance(ManagedBeanRegistryImpl.java:155)
at org.hi...@6.1.5.Final//org.hibernate.mapping.BasicValue.setExplicitCustomType(BasicValue.java:828)
at org.hi...@6.1.5.Final//org.hibernate.cfg.annotations.BasicValueBinder.fillSimpleValue(BasicValueBinder.java:1238)
at org.hi...@6.1.5.Final//org.hibernate.cfg.SetBasicValueTypeSecondPass.doSecondPass(SetBasicValueTypeSecondPass.java:26)
at org.hi...@6.1.5.Final//org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1782)
at org.hi...@6.1.5.Final//org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1729)
at org.hi...@6.1.5.Final//org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:300)
at org.hi...@6.1.5.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:1350)
at org.hi...@6.1.5.Final//org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:1421)
at org.hibernate.ji...@27.0.1.Final//org.jboss.as.jpa.hibernate.TwoPhaseBootstrapImpl.build(TwoPhaseBootstrapImpl.java:45)
at org.jbos...@27.0.1.Final//org.jboss.as.jpa.service.PersistenceUnitServiceImpl$1$1.run(PersistenceUnitServiceImpl.java:171)
... 10 more
Caused by: java.lang.NullPointerException: Cannot invoke "jakarta.enterprise.inject.spi.BeanManager.createCreationalContext(jakarta.enterprise.context.spi.Contextual)" because "this.beanManager" is null
at org.hi...@6.1.5.Final//org.hibernate.resource.beans.container.internal.JpaCompliantLifecycleStrategy$NamedBeanImpl.initialize(JpaCompliantLifecycleStrategy.java:228)
”
( https://hibernate.atlassian.net/browse/HHH-16069#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16069#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#100214- sha1:5a2a1e8 )
1 year, 8 months