[JIRA] (HHH-16811) Dirty property lost and not detected with Batch Fetch, Embedded and FetchMode SELECT
by Jones (JIRA)
Jones ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... ) *updated* an issue
Hibernate ORM ( https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiNDU3ZWU3OGZh... ) / Bug ( https://hibernate.atlassian.net/browse/HHH-16811?atlOrigin=eyJpIjoiNDU3ZW... ) HHH-16811 ( https://hibernate.atlassian.net/browse/HHH-16811?atlOrigin=eyJpIjoiNDU3ZW... ) Dirty property lost and not detected with Batch Fetch, Embedded and FetchMode SELECT ( https://hibernate.atlassian.net/browse/HHH-16811?atlOrigin=eyJpIjoiNDU3ZW... )
Change By: Jones ( https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%... )
The dirty property is lost (reset) in {{BatchEntityInsideEmbeddableSelectFetchInitializer}}.{{updateRootEntityLoadedState}} (maybe the same could happen in {{BatchEntitySelectFetchInitializer}}.{{updateParentEntityLoadedState}}) for the following scenario:
{code:java}// initial investigation started with dynamic update since there were other dirty properties
// but this minimal test case also fails without dynamic update since myEmbeddable is the only dirty property in this test case
@org.hibernate.annotations.DynamicUpdate
@Entity
@Table(name = "ENTITY_A")
public class EntityA {
@Id
@Column(name = "ID")
Integer id;
@Embedded
MyEmbeddableComponent myEmbeddable;
@JoinColumn(name = "ENTITY_B")
@ManyToOne
EntityB entityB;
}
@Entity
@Table(name = "ENTITY_B")
public class EntityB {
@Id
@Column(name = "ID")
Integer id;
@OneToMany(mappedBy = "entityB")
final List<EntityA> listOfEntityA = new ArrayList<>();
}
@Entity
@Table(name = "ENTITY_C")
public class EntityC {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID")
Integer id;
}
@Embeddable
public class MyEmbeddableComponent {
@Column(name = "MY_EMB_REF")
String embRef;
@ManyToOne
@JoinColumn(name = "ENTITY_C")
@Fetch(FetchMode.SELECT)
EntityC entityC;
}{code}
{code:java} @Override
protected void configure(Configuration configuration) {
super.configure(configuration);
configuration.setProperty(AvailableSettings.SHOW_SQL, Boolean.TRUE.toString());
configuration.setProperty(AvailableSettings.FORMAT_SQL, Boolean.TRUE.toString());
configuration.setProperty(AvailableSettings.DEFAULT_BATCH_FETCH_SIZE, "2");
}
@Test
public void hhhXXXTest() throws Exception {
Integer idA = 1;
Integer idB = 2;
try (Session s = openSession()) {
Transaction tx = s.beginTransaction();
MyEmbeddableComponent embeddable = new MyEmbeddableComponent();
embeddable.embRef = "some-ref";
EntityA entityA = new EntityA();
EntityB entityB = new EntityB();
EntityC entityC = new EntityC();
embeddable.entityC = entityC;
entityA.id = idA;
entityA.myEmbeddable = embeddable;
entityA.entityB = entityB;
entityB.id = idB;
entityB.listOfEntityA.add(entityA);
s.persist(entityC);
s.persist(entityB);
s.persist(entityA);
tx.commit();
}
try (Session s = openSession()) {
Transaction tx = s.beginTransaction();
EntityA entityA = s.find(EntityA.class, idA);
entityA.myEmbeddable = null;
EntityB entityB = s.find(EntityB.class, idB);
// the following lazy loading will initialize the collection and it will reset
// the entityA state, losing the dirtied myEmbeddable property value
assertThat(entityB.listOfEntityA).hasSize(1);
tx.commit();
}
try (Session s = openSession()) {
EntityA entityA = s.find(EntityA.class, idA);
assertThat(entityA.myEmbeddable).isNull();
}
}{code}
{noformat}org.opentest4j.AssertionFailedError:
Expecting:
<org.hibernate.bugs.MyEmbeddableComponent@65d0a110>
to be equal to:
<null>
but was not.
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at org.hibernate.bugs.ORMUnitTestCase.hhhXXXTest(ORMUnitTestCase.java:100)
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.hibernate.testing.junit4.ExtendedFrameworkMethod.invokeExplosively(ExtendedFrameworkMethod.java:45)
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.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:299)
at org.junit.internal.runners.statements.FailOnTimeout$CallableStatement.call(FailOnTimeout.java:293)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.lang.Thread.run(Thread.java:833){noformat}
This used to work just fine with latest 5.6 hibernate series.
The failing test case will be attached and also available at [https://github.com/ratoaq2/HHH-16811|https://github.com/ratoaq2/HHH-16811...]
( https://hibernate.atlassian.net/browse/HHH-16811#add-comment?atlOrigin=ey... ) Add Comment ( https://hibernate.atlassian.net/browse/HHH-16811#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#100227- sha1:5147d46 )
1 year, 3 months