[JIRA] (HHH-16901) Hibernate 6 : Embedded field not correctly instantiated
by geoffrey deremetz (JIRA)
geoffrey deremetz ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea439b... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYmUwZjgwN2Fi... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16901?atlOrigin=eyJpIjoiYmUwZj... ) HHH-16901 ( https://hibernate.atlassian.net/browse/HHH-16901?atlOrigin=eyJpIjoiYmUwZj... ) Hibernate 6 : Embedded field not correctly instantiated ( https://hibernate.atlassian.net/browse/HHH-16901?atlOrigin=eyJpIjoiYmUwZj... )
Change By: geoffrey deremetz ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=5ea439b... )
Spring boot 3.1.1 - Hibernate 6.2.5.Final
Embedded field are not correctly instantiated when entity is used in a composite key
{noformat}@Entity
@Table(name = "trip")
public class Trip {
@Id
public Long id;
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "date", column = @Column(name = "date_position1")),
})
@AssociationOverride(name = "poi", joinColumns = @JoinColumn(name = "poi1_id_fk"))
public Location position1 = new Location();
@Embedded
@AttributeOverrides({
@AttributeOverride(name = "date", column = @Column(name = "date_position2")),
})
@AssociationOverride(name = "poi", joinColumns = @JoinColumn(name = "poi2_id_fk"))
public Location position2 = new Location();
}{noformat}
in certain scenarios (see my code attached), trip.position2 is null when it shouldn't be ({{poi2_id_fk}} is null but not {{date_position2}})
scenario 1 (working)
{noformat} Trip trip = tripRepository.findById(1L).orElseThrow();
assertThat(trip.position1).isNotNull();
assertThat(trip.position2).isNotNull();{noformat}
scenario 2 (not working)
{noformat}@Entity
@Table(name = " report")
public class Report {
@Id
public Long id;
@OneToMany(mappedBy = "compositeKey.report", cascade = ALL, orphanRemoval = true, fetch = FetchType.EAGER)
public List<ReportTrip> reportTripList;
}
@Entity
@Table(name = " report_trip")
public class ReportTrip {
@EmbeddedId
public ReportTripId compositeKey = new ReportTripId();
@Column(name = "other")
public String other;
}
@Embeddable
public class ReportTripId implements Serializable {
@ManyToOne
@JoinColumn(name = "report_id_fk")
public Report report;
@ManyToOne
@JoinColumn(name = "trip_id_fk")
public Trip trip;
}{noformat}
{noformat} Optional<Report> reportOptional = repository.findById(1L);
assertThat(reportOptional).isPresent();
Report report = reportOptional.get();
assertThat(report.reportTripList.get(0).compositeKey.trip.position1).isNotNull();
assertThat(report.reportTripList.get(0).compositeKey.trip.position2).isNotNull(); // ko{noformat}
( https://hibernate.atlassian.net/browse/HHH-16901#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16901#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#100230- sha1:e339e49 )
2 years, 9 months
[JIRA] (HHH-16897) Delete query for entity using table-per-class inheritance may result in NullPointerException
by Marko Bekhta (JIRA)
Marko Bekhta ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDQ0NGUxMjQ0... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16897?atlOrigin=eyJpIjoiNDQ0NG... ) HHH-16897 ( https://hibernate.atlassian.net/browse/HHH-16897?atlOrigin=eyJpIjoiNDQ0NG... ) Delete query for entity using table-per-class inheritance may result in NullPointerException ( https://hibernate.atlassian.net/browse/HHH-16897?atlOrigin=eyJpIjoiNDQ0NG... )
Change By: Marko Bekhta ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
Having a model like:
{code:java}@Entity(name = "tpc_supert")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public static class TablePerClassSuperType {
@Id
@GeneratedValue
private Long id;
}
@Entity(name = "tpc_subt")
public static class TablePerClassSubType extends TablePerClassSuperType {
}{code}
And then trying to execute:
{noformat}Query<?> query = session.createQuery( "delete from " + TablePerClassSuperType.class.getName() + " e where type( e ) = :type" );
query.setParameter( "type", TablePerClassSuperType.class );
query.executeUpdate();{noformat}
results in:
{noformat}java.lang.NullPointerException
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.contextAllowsTreatOrFilterEntityNameUse(BaseSqmToSqlAstConverter.java:3129)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.registerEntityNameUsage(BaseSqmToSqlAstConverter.java:3082)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.registerEntityNameUsage(BaseSqmToSqlAstConverter.java:3050)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.handleTypeComparison(BaseSqmToSqlAstConverter.java:7358)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitComparisonPredicate(BaseSqmToSqlAstConverter.java:7336)
at org.hibernate.query.sqm.sql.BaseSqmToSqlAstConverter.visitComparisonPredicate(BaseSqmToSqlAstConverter.java:436)
at org.hibernate.query.sqm.tree.predicate.SqmComparisonPredicate.accept(SqmComparisonPredicate.java:104)
at org.hibernate.query.sqm.mutation.internal.MultiTableSqmMutationConverter.visitWhereClause(MultiTableSqmMutationConverter.java:218)
at org.hibernate.query.sqm.mutation.internal.temptable.RestrictedDeleteExecutionDelegate.execute(RestrictedDeleteExecutionDelegate.java:146)
at org.hibernate.query.sqm.mutation.internal.temptable.TableBasedDeleteHandler.execute(TableBasedDeleteHandler.java:64)
at org.hibernate.query.sqm.mutation.internal.temptable.LocalTemporaryTableMutationStrategy.executeDelete(LocalTemporaryTableMutationStrategy.java:65)
at org.hibernate.query.sqm.internal.MultiTableDeleteQueryPlan.executeUpdate(MultiTableDeleteQueryPlan.java:36)
at org.hibernate.query.sqm.internal.QuerySqmImpl.doExecuteUpdate(QuerySqmImpl.java:703)
at org.hibernate.query.sqm.internal.QuerySqmImpl.executeUpdate(QuerySqmImpl.java:673)
at org.hibernate.orm.test.hql.DeleteWhereFunctionCallTest.lambda$testDeleteWhereTypeFunctionCall2$6(DeleteWhereFunctionCallTest.java:91)
at org.hibernate.testing.orm.transaction.TransactionUtil.wrapInTransaction(TransactionUtil.java:49)
at org.hibernate.testing.orm.transaction.TransactionUtil.inTransaction(TransactionUtil.java:24)
at org.hibernate.testing.orm.junit.SessionFactoryExtension$SessionFactoryScopeImpl.inTransaction(SessionFactoryExtension.java:375)
at org.hibernate.testing.orm.junit.SessionFactoryExtension$SessionFactoryScopeImpl.inTransaction(SessionFactoryExtension.java:352)
at org.hibernate.orm.test.hql.DeleteWhereFunctionCallTest.testDeleteWhereTypeFunctionCall2(DeleteWhereFunctionCallTest.java:87)
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.platform.commons.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:727)
at org.junit.jupiter.engine.execution.MethodInvocation.proceed(MethodInvocation.java:60)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$ValidatingInvocation.proceed(InvocationInterceptorChain.java:131)
at org.junit.jupiter.engine.extension.TimeoutExtension.intercept(TimeoutExtension.java:156)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestableMethod(TimeoutExtension.java:147)
at org.junit.jupiter.engine.extension.TimeoutExtension.interceptTestMethod(TimeoutExtension.java:86)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker$ReflectiveInterceptorCall.lambda$ofVoidMethod$0(InterceptingExecutableInvoker.java:103)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.lambda$invoke$0(InterceptingExecutableInvoker.java:93)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain$InterceptedInvocation.proceed(InvocationInterceptorChain.java:106)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.proceed(InvocationInterceptorChain.java:64)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.chainAndInvoke(InvocationInterceptorChain.java:45)
at org.junit.jupiter.engine.execution.InvocationInterceptorChain.invoke(InvocationInterceptorChain.java:37)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:92)
at org.junit.jupiter.engine.execution.InterceptingExecutableInvoker.invoke(InterceptingExecutableInvoker.java:86)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.lambda$invokeTestMethod$7(TestMethodTestDescriptor.java:217)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.invokeTestMethod(TestMethodTestDescriptor.java:213)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:138)
at org.junit.jupiter.engine.descriptor.TestMethodTestDescriptor.execute(TestMethodTestDescriptor.java:68)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:151)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1541)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
at org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
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.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74){noformat}
A reproducer is here [https://github.com/hibernate/hibernate-orm/pull/6944|https://github.com/h...]
( https://hibernate.atlassian.net/browse/HHH-16897#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16897#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#100230- sha1:e339e49 )
2 years, 9 months