Reputation: 49097
When calling EntityManager.flush(), will it flush the second level cache too? I tried Googling and I also tried flushing it and it seems like it does, but it would be good to have it confirmed.
Edit: Now it does not seem like it flush the second level cache.
Upvotes: 7
Views: 449
Reputation: 15577
The L2 cache ought (by default, in any sensible JPA implementation) to be updated at commit not flush, but this is not mandated in the JPA2 spec, so you're down to implementation specifics. DataNucleus certainly only updates it at commit. If an L2 cache was updated at flush, and then those objects changes rolled back, this leads to potential invalid/non-persistent data being read. Some may allow that as an option.
Upvotes: 0
Reputation: 2174
JPA has no notion of a second-level cache (it isn't part of the spec). So the behavior of the second-level cache depends entirely upon the JPA provider. What are you using Hibernate, EclipseLink, OpenJPA?
Update: I stand partially corrected, JPA 2.0 introduces a few options to control second-level cache usage (like @Cachable)
Upvotes: 1