Shortly, I have an entity mapped to view in DB (Oracle) with enabled 2nd level Cache (read only strategy) -- ehcache.
If I manually update some column in DB -- cache will not be updated.
I did not find any ways to do this. Only if updates will be done through Hibernate entity.
May I somehow implement this feature?
Maybe Job to monitor table (or view)? Or maybe there is some method to notify Hibernate about change in DB in concrete table.
Thanks for future answers!
According to Hibernate JavaDoc, you can use
org.hibernate.Cache.evictAllRegions()
:Using Session and SessionFactory:
1) If you need update only one entity (if directly from db you will update only certain entities) not whole session, you can use
2) If you have a lot of entities, that can be updated directly from db you can use this method that evicts all entities from 2nd level cache (we can expose this method to admins through JMX or other admin tools):
3) here another apporche described here for postgresql+hibernate, I think similar you can do for Oracle like this
You can use
session.refresh()
method to reload the objects which are currently held in session.Read object loading for more detail.
You will find here the way to control the second level cache:
http://docs.jboss.org/hibernate/core/3.3/reference/en/html/performance.html#performance-sessioncache