Flush() Vs Commit()
flush()
will send the the changes to the database but not commiting yet
commit()
will commit those changes into the database. This will automatically call flush()
as well
By default of a @Transactional. After a transaction ends it will automatically commit()
.
What happen between flush() and commit()
These are the UNCOMMITED
changes. Since Transaction are executed in isolation, when you call flush()
but haven't called commit()
yet, the other transaction might or might not see the changes depends on the isolation level:
READ_UNCOMMITED
: will see the changes fromflush()
READ_COMMITED
: will not see the changes fromflush()
If the other transaction don't specify, the default behavior of Spring is to use DEFAULT
which will use the database default's isolation.