I have a jdbc update query which updates a table. And entity cache is maintained for the same table in hibernate. I need to tell hibernate to refresh the cache region for that entity which is updated by the jdbc query.

1

There are 1 answers

0
Radim Vansa On

You're looking for

sessionFactory.getCache().evictEntityRegion(MyEntity.class)

This removes the stale entries from cache. However, if you do that before JDBC update, in the window between this invalidation and the JDBC update, the cache can be populated again by concurrent reads, so if your application does not stop all DB accesses, you could end up with some stale entries.

Another region eviction after the update could sort it out, but between the JDBC query and region eviction you're prone to inconsistent data in the cache, again.