Reputation: 1891
A bit confused with the entityManger.flush();
Hibernate doc for batching
https://docs.jboss.org/hibernate/orm/5.0/userguide/html_single/chapters/batch/Batching.html
"When you make new objects persistent, employ methods flush() and clear() to the session regularly, to control the size of the first-level cache."
I am working on spring boot data jpa.
The first doubt is for Restful applications first level cache is enabled or not?
Can the entityManager.flush()
clears the second level cache?
Is entityManger.flush()
is similar to System.gc()
;
Upvotes: 2
Views: 1159
Reputation: 26532
1) First level cache is created per started transaction, so its always there for each transactional method.
2) entityManager.flush()
, does not clear the second level cache. It also does not clear the first level cache, it enforces any changes done in the current transaction to be pushed into the physical database.
3) Is entityManger.flush()
is similar to System.gc()
? No, all the objects are still on the heap and are even still managed by the current persistence context.
Upvotes: 3