Hello,
I am currently upgrading to Hibernate 6.2.1.Final from 5.2.5.Final. I am having the following error:
[31-12-23 14:09:09.979] INFO com.app.framework.backend.interceptor.SessionBeanInterceptor - NullPointerException when invoking ArchiveSessionBean#archiveByOption : Cannot invoke "org.hibernate.sql.results.graph.Fetch.createAssembler(org.hibernate.sql.results.graph.FetchParentAccess, org.hibernate.sql.results.graph.AssemblerCreationState)" because "versionFetch" is null
[31-12-23 14:09:10.221] INFO com.app.framework.backend.interceptor.SessionBeanInterceptor - EJBTransactionRolledbackException when invoking ContactSessionBean#performContactArchiving : Cannot invoke "org.hibernate.sql.results.graph.Fetch.createAssembler(org.hibernate.sql.results.graph.FetchParentAccess, org.hibernate.sql.results.graph.AssemblerCreationState)" because "versionFetch" is null
[31-12-23 14:09:10.234] INFO com.app.framework.backend.interceptor.SessionBeanInterceptor - EJBTransactionRolledbackException when invoking ContactSessionBean#deleteContact : Cannot invoke "org.hibernate.sql.results.graph.Fetch.createAssembler(org.hibernate.sql.results.graph.FetchParentAccess, org.hibernate.sql.results.graph.AssemblerCreationState)" because "versionFetch" is null
[31-12-23 14:09:10.249] INFO com.app.framework.backend.interceptor.SessionBeanInterceptor - EJBTransactionRolledbackException when invoking AnonymizationSessionBean#deleteEntity : Cannot invoke "org.hibernate.sql.results.graph.Fetch.createAssembler(org.hibernate.sql.results.graph.FetchParentAccess, org.hibernate.sql.results.graph.AssemblerCreationState)" because "versionFetch" is null
[31-12-23 14:09:10.262] ERROR com.app.contact.server.manager.ContactManager -
jakarta.ejb.EJBTransactionRolledbackException: Cannot invoke "org.hibernate.sql.results.graph.Fetch.createAssembler(org.hibernate.sql.results.graph.FetchParentAccess, org.hibernate.sql.results.graph.AssemblerCreationState)" because "versionFetch" is null
at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:219) ~[wildfly-ejb3-28.0.1.Final.jar!/:28.0.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:392) ~[wildfly-ejb3-28.0.1.Final.jar!/:28.0.1.Final]
at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:160) ~[wildfly-ejb3-28.0.1.Final.jar!/:28.0.1.Final]
at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:422) ~[jboss-invocation-2.0.0.Final.jar!/:2.0.0.Final]
at org.jboss.invocation.InterceptorContext$Invocation.proceed(InterceptorContext.java:509) ~[?:?]
at org.jboss.weld.module.ejb.AbstractEJBRequestScopeActivationInterceptor.aroundInvoke(AbstractEJBRequestScopeActivationInterceptor.java:72) ~[weld-ejb-5.1.0.Final.jar!/:5.1.0.Final]
// JBOSS stack
at com.app.contact_manager.common.ifc.AnonymizationSession$$$view69.performConfirmAnonymization(Unknown Source) [core-noc-contact_manager-trunk-SNAPSHOT.jar:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[?:?]
at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
at java.lang.reflect.Method.invoke(Method.java:568) ~[?:?]
at com.app.scheduler.common.core.AbstractJob.directExecution(AbstractJob.java:812) [core-app-scheduler-trunk-SNAPSHOT.jar:?]
at com.app.scheduler.common.core.AbstractJob._execute(AbstractJob.java:322) [core-app-scheduler-trunk-SNAPSHOT.jar:?]
at com.app.scheduler.common.core.AbstractJob.execute(AbstractJob.java:178) [core-app-scheduler-trunk-SNAPSHOT.jar:?]
at com.app.scheduler.common.core.AbstractJob.execute(AbstractJob.java:138) [core-app-scheduler-trunk-SNAPSHOT.jar:?]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [external-quartz-2.3.2.jar:?]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [external-quartz-2.3.2.jar:?]
Caused by: java.lang.NullPointerException: Cannot invoke "org.hibernate.sql.results.graph.Fetch.createAssembler(org.hibernate.sql.results.graph.FetchParentAccess, org.hibernate.sql.results.graph.AssemblerCreationState)" because "versionFetch" is null
at org.hibernate.sql.results.graph.entity.AbstractEntityInitializer.<init>(AbstractEntityInitializer.java:143) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.results.graph.entity.internal.EntityResultInitializer.<init>(EntityResultInitializer.java:36) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.results.graph.entity.internal.EntityResultImpl.lambda$createResultAssembler$0(EntityResultImpl.java:91) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.results.internal.ResultsHelper$1.resolveInitializer(ResultsHelper.java:108) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.results.graph.entity.internal.EntityResultImpl.createResultAssembler(EntityResultImpl.java:82) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.results.jdbc.internal.StandardJdbcValuesMapping.resolveAssemblers(StandardJdbcValuesMapping.java:53) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.results.internal.ResultsHelper.createRowReader(ResultsHelper.java:78) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.results.internal.ResultsHelper.createRowReader(ResultsHelper.java:64) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.doExecuteQuery(JdbcSelectExecutorStandardImpl.java:341) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.executeQuery(JdbcSelectExecutorStandardImpl.java:168) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.exec.internal.JdbcSelectExecutorStandardImpl.list(JdbcSelectExecutorStandardImpl.java:93) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.sql.exec.spi.JdbcSelectExecutor.list(JdbcSelectExecutor.java:31) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.loader.ast.internal.DatabaseSnapshotExecutor.loadDatabaseSnapshot(DatabaseSnapshotExecutor.java:174) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.loader.ast.internal.SingleIdEntityLoaderSupport.loadDatabaseSnapshot(SingleIdEntityLoaderSupport.java:39) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.getDatabaseSnapshot(AbstractEntityPersister.java:1840) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.engine.internal.StatefulPersistenceContext.getDatabaseSnapshot(StatefulPersistenceContext.java:318) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:306) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.engine.internal.ForeignKeys$Nullifier.isNullifiable(ForeignKeys.java:241) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.engine.internal.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:110) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.engine.internal.ForeignKeys$Nullifier.nullifyTransientReferences(ForeignKeys.java:75) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.event.internal.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:394) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.event.internal.DefaultDeleteEventListener.delete(DefaultDeleteEventListener.java:242) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.event.internal.DefaultDeleteEventListener.deletePersistentInstance(DefaultDeleteEventListener.java:219) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.event.internal.DefaultDeleteEventListener.delete(DefaultDeleteEventListener.java:159) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:95) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:83) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:127) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:961) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:892) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.hibernate.internal.SessionImpl.remove(SessionImpl.java:2354) ~[hibernate-core-6.2.1.Final.jar!/:6.2.1.Final]
at org.jboss.as.jpa.container.AbstractEntityManager.remove(AbstractEntityManager.java:658) ~[wildfly-jpa-28.0.1.Final.jar!/:28.0.1.Final]
I’m trying to delete contact and its child entites. Every entity gets deleted without problem except below case:
Contact has OneToMany relationship with ContactRelationship.
We store one generic ContactRelationship for all contact which creates problem while deleting.
@OneToMany(mappedBy = “contact”)
protected Collection contactRelationship = new ArrayList();
@ManyToOne
@JoinColumn(name = “CONTACT_ID_A”)
protected Contact contact;
I’m using entityManager.remove(entityToDelete);
to delete the child entities.
Our code has been like this since Hibernate 5 and it hasn’t changed.
We recently upgraded to Hibernate 6.2.1 and began to see this kind of NPE when debugging.
Peeking at the source code of AbstractEntityInitializer.java (line 143 as of hibernate-core version 6.2.1.Final),
versionFetch is null when it is generic ContactRelationship.
Here is the constructor of AbstractEntityInitializer
that I peeked at:
final EntityVersionMapping versionMapping = entityDescriptor.getVersionMapping();
if ( versionMapping != null ) {
final Fetch versionFetch = resultDescriptor.findFetch( versionMapping );
// If there is a version mapping, there must be a fetch for it
assert versionFetch != null;
versionAssembler = versionFetch.createAssembler( this, creationState );
}
I am wondering is it a bug in the Hibernate or I am doing something wrong. Relations like above used to work with the previously stated version of Hibernate.
Any pointer would be very helpful.
Regards,
Raushan