-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Defer EntityManager flushing and clearing in JpaPagingItemReader [BATCH-1110] #2465
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hamdi Makni commented Finally, i used a ChunkListener: import java.util.HashMap; import javax.persistence.EntityManager; import org.springframework.batch.core.listener.ChunkListenerSupport; /**
*/
} |
Dave Syer commented Isn't this problem a little more subtle? Unless the page size is aligned with the commit interval, then flush and clear should either always happen, or only in a transaction synchronization (which might be already provided by the transaction manager?). |
Thomas Risberg commented It is much more subtle. We need to switch the paging reader to use a shared transactional em and make sure the transaction commits don't clear the session. This requires an extended persistence context that we must share between the reader, processor and writer. We would also have to consider any classes that use To accomplish this requires a lot more work. Maybe for a 2.1 release. -Thomas |
Thomas Risberg commented Thinking about it some more - there are two separate issues.
I think what Hamdi was asking for was #1 while my earlier comments addressed #2. I'll create another issue for the extended persistence context (#2) and will solve #1 for now. I can simply move the clear to before the page is read rather than after. This should work fine in all cases. -Thomas |
Thomas Risberg commented moved flush/clear to before page read to allow for lazy-loading of properties of page result items |
Hamdi Makni opened BATCH-1110 and commented
We can add clearAfterFlush with default value = true in the JpaPagingItemReader and just make a simple test before clearing the entity manager:
if (clearAfterFlush)
entityManager.clear();
a StepListener (using StepListenerSupport) can be added to the step to clear the EntityManager after writing.
I'll write this listener and post it to this issue later
Affects: 2.0.0.M4
Reference URL: http://forum.springframework.org/showthread.php?t=68138
Issue Links:
The text was updated successfully, but these errors were encountered: