I am using JPA EntityManager with Spring/Hibernate and entitymanager seems to be behaving weird when I update an entity from a hibernate session and then view it from a different hibernate session.
I have the following configuration in my application:
- EHCache, and enabled Second Level Cache
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
on the entities- Extended
PersistenceContext
onem
OpenEntityManagerInViewFilter
Calling em.clear()
solves this issue. I tried disabling second level caching, query caching etc but did not help. I expected the entitymanager to take care of this. Is this expected ? I am looking for a cleaner approach, and do away with calling em.clear()
.