Skip to content

FIX: Recursive batch flush can save beans in wrong order#3148

Merged
rbygrave merged 1 commit intoebean-orm:masterfrom
FOCONIS:fix-recursive-batch-flush
Aug 14, 2023
Merged

FIX: Recursive batch flush can save beans in wrong order#3148
rbygrave merged 1 commit intoebean-orm:masterfrom
FOCONIS:fix-recursive-batch-flush

Conversation

@rPraml
Copy link
Contributor

@rPraml rPraml commented Aug 8, 2023

if you try to save a persist graph, you normally expect, that the elements are in a logical order.

Here:

  • save customer 1
  • save contacts a,b,c of customer 1
  • save customer 2
  • save contacts d,e,f of customer 2
    OR
  • save customer 1+2
  • save contacts a,b,c of customer 1 + d,e,f of customer 2

This works fine, if no batch flush occur.

Now, it can happen, that during save of customer 1, something (a DB.find in a postInsert hook, a lazy load) triggers a batch flush, which causes to process all internal save queues NOW.
As ebean is currently processing the "customer" query, and the next step of saving customer 2 is interrupted by the flush,
ebean tries to save contact a,b,c + d,e,f - the later three will fail, because customer 2 is not yet saved and has no ID.

As suggested solution, we disable transaction.setFlushOnQuery in the executeNow.

Roland


Co-authored-by: Noemi Praml noemi.praml@foconis.de
Co-authored-by: Roland Praml roland.praml@foconis.de

rPraml added a commit to FOCONIS/ebean that referenced this pull request Aug 10, 2023
@rob-bygrave rob-bygrave added this to the 13.20.2 milestone Aug 11, 2023
@rbygrave rbygrave merged commit b8e164e into ebean-orm:master Aug 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants