Has the Hibernate Team ever tested to remove the above order enforcement, and simply flush as per the order of entity changes in the application code, to see what would happen regarding the chance of contraint violations?
All the examples (not many) I saw regarding this topic does seem that code order would work, like in A beginner’s guide to Hibernate flush operation order (of yours) in which if the image was removed first before adding the other, as per the code, there would be no constraint violation.