advancedThe Persistence Context — First-Level Cache, Dirty Checking & Flush
Why can a long-running batch job that processes thousands of entities in one transaction run into memory problems?
The persistence context holds every loaded/managed entity (plus its load-time snapshot for dirty checking) for the entire life of the unit of work — processing thousands of entities in one transaction with no cleanup means all of them accumulate in memory simultaneously. The fix is periodically calling flush() followed by clear() to sync pending changes and release the accumulated entities from the persistence context.
This is a Pro chapter
Sign in, then upgrade to Pro or Power to unlock this and the full Spring Ecosystem Mastery library.
Why can a long-running batch job that processes thousands of entities in one transaction run into memory problems?