-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Using second-level cache "read-write"
PostPosted: Mon Dec 06, 2004 4:40 pm 
Beginner
Beginner

Joined: Tue Sep 09, 2003 5:28 pm
Posts: 33
Location: Cincinnati, OH
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>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.