79517601

Date: 2025-03-18 13:35:40
Score: 1
Natty:
Report link

few approaches to fix this issue:

@OneToMany(mappedBy = "test1Id", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)

private Set<Test2> contacts = new HashSet<>();

2.Modify the persistence code to explicitly control the order


db.persist(test1);
db.flush(); // Force flush to ensure Test1 is in the database
db.persist(test2);

3.Use @MapsId for the child entity

@ManyToOne(fetch = FetchType.LAZY)
@MapsId("objectId") // assuming your embedded ID has an objectId field
@JoinColumn(name = "object_id")
private Test1 test1Id;

Check your Hibernate configuration
In Hibernate 6, check if you have changed any settings related to order operations or batch processing. The property hibernate.order_inserts might be relevant here.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @MapsId
  • Low reputation (1):
Posted by: Sahil Chotaliya