Hi there,
I am using the second-level cache (ehcache) in Hibernate2.1, <cache usage="read-write"/>, after update an object; I have to use SessionFactry.evict(object) to clean the old cached data for keeping the data consistent with the database. I wander if this is the right way to do it? Or we might not need to clean it up manually, hibernate will know the difference by itself, if that is the case, how to get it work, because I tried, it seemed like to me not working at all.
Thanks very much!
Code:
Session session = sessionFactory.openSession();
TimeControlCache tc = (TimeControlCache)session.get(TimeControlCache.class, "1");
tc.setIndirectCostRate(new BigDecimal(175.00));
Transaction tx= session.beginTransaction();
session.saveOrUpdate(tc);
tx.commit();
session.close();
sessionFactory.evict(TimeControlCache.class);
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.TimeControlCache" table="timctl">
<cache usage="read-write"/>
<id name="standardRateCode" column="t@strc">
<generator class="assigned"/>
</id>
<property name="indirectCostRate" column="t@ndrt"/>
</class>
</hibernate-mapping>