After updating from 5.4.16 to 5.4.17 we had several unit tests failing in one of our projects. I did some investigation and came up with a minimum scenario and test case that reproduces the problem:
@Entity
public class Child {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotNull
@ManyToOne
private Parent parent;
public void setParent(Parent parent) {
this.parent = parent;
}
}
@Entity
public class Parent {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne(cascade = CascadeType.ALL)
private Child child;
public Parent(Child child) {
this.child = child;
this.child.setParent(this);
}
public Child getChild() {
return child;
}
}
And a test case:
@ExtendWith(SpringExtension.class)
public class ParentChildTest {
@Test
@Transactional
public void save() {
Parent parent = new Parent(new Child());
sessionFactory.getCurrentSession().save(parent);
sessionFactory.getCurrentSession().setHibernateFlushMode(FlushMode.MANUAL);
sessionFactory.getCurrentSession().flush();
}
@Resource
private SessionFactory sessionFactory;
}
With 5.4.16 the following statements are executed and the test completes successfully
insert into parent (id, child_id) values (null, ?)
insert into child (id, parent_id) values (null, ?)
update parent set child_id=? where id=?
With 5.4.17 the result is
If the @NotNulll annotation is removed the entities are saved without any problem, only in a different order
insert into child (id, parent_id) values (null, ?)
insert into parent (id, child_id) values (null, ?)
update child set parent_id=? where id=?
It seems to be related with the fix provided by HHH-10956 Closed |