Jones (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
) *created* an issue
Hibernate ORM (
https://hibernate.atlassian.net/browse/HHH?atlOrigin=eyJpIjoiYjI5MzBhZGE1...
) / Bug (
https://hibernate.atlassian.net/browse/HHH-16575?atlOrigin=eyJpIjoiYjI5Mz...
) HHH-16575 (
https://hibernate.atlassian.net/browse/HHH-16575?atlOrigin=eyJpIjoiYjI5Mz...
) Batch fetch with FlushMode COMMIT overrides/discards dirtied ManyToOne property (
https://hibernate.atlassian.net/browse/HHH-16575?atlOrigin=eyJpIjoiYjI5Mz...
)
Issue Type: Bug Affects Versions: 6.2.2 Assignee: Unassigned Components: query-hql
Created: 09/May/2023 10:14 AM Priority: Critical Reporter: Jones (
https://hibernate.atlassian.net/secure/ViewProfile.jspa?accountId=557058%...
)
@Entity
@Table(name = "ENTITY_A" )
public class EntityA {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID" )
Integer id;
@Column(name = "FOO" )
Integer foo;
@JoinColumn(name = "CURRENT_ENTITY_B" )
@ManyToOne
EntityB currentEntityB;
// not needed for bug report
// @OneToMany(mappedBy = "entityA" )
// List<EntityB> listOfEntitiesB = new ArrayList<>();
}
@Entity
@Table(name = "ENTITY_B" )
public class EntityB {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID" )
Integer id;
@JoinColumn(name = "ENTITY_A" )
@ManyToOne
EntityA entityA;
}
@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, "10" );
configuration.setProperty(HibernateHints.HINT_FLUSH_MODE, FlushMode.COMMIT.name());
}
@Test
public void hhhXXXXTest() throws Exception {
Integer currentBId;
try (Session s = openSession()) {
Transaction tx = s.beginTransaction();
EntityA entityA1 = new EntityA();
EntityB entityB1 = new EntityB();
entityB1.entityA = entityA1;
entityA1.currentEntityB = entityB1;
s.persist(entityA1);
s.persist(entityB1);
s.flush();
entityA1.foo = 123;
EntityB entityB2 = new EntityB();
entityB2.entityA = entityA1;
entityA1.currentEntityB = entityB2;
s.persist(entityB2);
currentBId = entityB2.id;
List<EntityA> entitiesA = s.createQuery( "select a from EntityA a" ,
EntityA.class).getResultList();
assertThat(entitiesA).hasSize(1);
tx.commit();
}
try (Session s = openSession()) {
List<EntityA> entitiesA = s.createQuery( "select a from EntityA a" ,
EntityA.class).getResultList();
assertThat(entitiesA).hasSize(1);
assertThat(entitiesA.get(0).foo).isEqualTo(123);
assertThat(entitiesA.get(0).currentEntityB.id).isEqualTo(currentBId);
}
}
of course, disabling batch fetch or switching to default flush mode would avoid the
issue.
The problem happens because the first query loads the EntityA.currentEntityB in a batch
load which will use EntityB.entityA to override the parentInstance property.
Failing test scenario to be attached
(
https://hibernate.atlassian.net/browse/HHH-16575#add-comment?atlOrigin=ey...
) Add Comment (
https://hibernate.atlassian.net/browse/HHH-16575#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#100225- sha1:b79b7f6 )