-->
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: Curious query caching problem using ehcache.
PostPosted: Fri Oct 12, 2007 6:50 pm 
Newbie

Joined: Fri Oct 12, 2007 6:32 pm
Posts: 3
Not sure really how to describe this one, even the debug outputs look okay... here goes nothing!

Basically I'm running Hibernate 3.2.25GA, Hibernate Annotations 3.3.0 and ehcache 1.3.0. I have one simple query cached that returns a unique result which retrieves an object. I update a single column using a method in that object, and reload the page. Here is where everything goes a little haywire: entirely randomly, the OLD result pre-update is pulled from the cache. I may get 15 of the correct/current results, and then one of the old results. Sometimes it's two or three of the old results. I've spent many hours scouring documentation and debug output and have been unable to find any rhyme or reason as to why, randomly, I will get the old value.

Let me start with the simple method with the query I run:

Code:
      public Application getApplicationByDomainName(String domainName) {
         Session session = getSession();
         session.beginTransaction();
         Application app = null;
         app = (Application) session.createQuery("from Application app where app.serverAddr = :domainName")
               .setCacheable(true)
               .setCacheRegion("query.ApplicationManager")
               .setParameter("domainName", domainName).uniqueResult();
           session.getTransaction().commit();
         return app;


This returns an "Application" object, which has these annotations:

Code:
@Entity
@Table(name = "Settings")
@org.hibernate.annotations.Cache(usage =
   org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)


The application has very simple setter/getter methods for changing the simple string value-- and after changing the value I do a session.update()

And just for kicks, here is my hibernate mapping xml:

Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
   <property name="connection.username">sa</property>
   <property name="connection.password">1210Trac</property>
   <property name="connection.url">
      jdbc:jtds:sqlserver://zero:1433/ioffice control
   </property>
   <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
   <property name="hibernate.cache.use_query_cache">true</property>
   <property name="hibernate.c3p0.min_size">5</property>
    <property name="hibernate.c3p0.max_size">20</property>
    <property name="hibernate.c3p0.timeout">300</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>
   <property name="dialect">
      org.hibernate.dialect.SQLServerDialect
   </property>
   <property name="myeclipse.connection.profile">
      iofficeconnect
   </property>
   <property name="connection.driver_class">
      net.sourceforge.jtds.jdbc.Driver
   </property>
    <property name="show_sql">false</property>
    <property name="format_sql">false</property>
    <property name="use_sql_comments">false</property>
    <property name="current_session_context_class">thread</property>
   <mapping class="com.iofficeconnect.system.Application" />
   <mapping class="com.iofficeconnect.system.server.Server" />
   <mapping class="com.iofficeconnect.system.server.DBServer" />
   <mapping class="com.iofficeconnect.system.server.WebServer" />
   <mapping class="com.iofficeconnect.system.server.AppServer" />
</session-factory>
</hibernate-configuration>


and finally my ehcache.xml


Code:
<ehcache>
    <diskStore path="java.io.tmpdir"/>

    <defaultCache
            maxElementsInMemory="10000"
            eternal="false"
            timeToIdleSeconds="120"
            timeToLiveSeconds="120"
            overflowToDisk="true"
            diskSpoolBufferSizeMB="30"
            maxElementsOnDisk="10000000"
            diskPersistent="false"
            diskExpiryThreadIntervalSeconds="120"
            memoryStoreEvictionPolicy="LRU"
            />
    <cache
            name="org.hibernate.cache.UpdateTimestampsCache"
            maxElementsInMemory="5000"
            eternal="true"
            overflowToDisk="true"/>
</ehcache>


Again, when ehcache returns the old value instead of the current value the debug output looks EXACTLY the same.

If I'm leaving anything out (I can't think of anything), I apologize. Thank you all in advance for your help!

Daniel Jimenez


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.