I read it only for how the unidirectional associations work. Regarding this, the code
Post post = new Post("First post");
post.getComments().add(
new PostComment("My first review")
);
post.getComments().add(
new PostComment("My second review")
);
post.getComments().add(
new PostComment("My third review")
);
according to code change order would result in the following SQL
insert into post (title, id)
values ('First post', 1)
insert into post_comment (review, id)
values ('My first review', 2)
update post_comment set post_id = 1 where id = 2
insert into post_comment (review, id)
values ('My second review', 3)
update post_comment set post_id = 1 where id = 3
insert into post_comment (review, id)
values ('My third review', 4)
update post_comment set post_id = 1 where id = 4
in which case there are no constraint violation issues, consequently this example does not qualify to demonstrate that Hibernateās flush order is doing something special regarding preventing constraint violations.
I will wait for you to perhaps clarify this situation, or get me another example.
For point 3), I will wait for you to show me too.
Regarding āmulti-request logical transactionsā I will read it, then come back if anything relates to this topic.
I donāt remember proposing a āflush method call that really makes senseā ā¦ I just do not agree that calling flush manually is always a code smell, and do not agree that using update in place of delete and insert is always the best option.
In fact, the discussion around manual flush smells was divergent to my goal when creating this topic:
I just want to understand the reason behind Hibernateās flush order, which āwas chosen to minimize the chances of constraint violationsā.
Put simply: no evidence of Hibernateās flush order avoiding constraint violations was presented yet. This evidence must show Java code, and the corresponding SQL, the latter ordered as per Hibernateās flush order and avoiding a constraint violation that would occur if the SQL was flushed as per change order.
Please, lets focus on this, and forget the side-talk of code smells.
Only Gavin knows exactly why they implemented the ActionQueue like this 17 years ago. You should ask him on Twitter and see whether he gives you a more detailed explanation.
Iām going to end this topic since thereās nothing to add on my side.
Good luck digging the history of this design consideration. If you find a different explanation than what I already have you, you should definitely add it here or write an article about it. Anyway, no matter what the reason was, itās unlikely that it will ever change, so better understand how it works and how to get the most out of it.