3 Replies Latest reply on Oct 3, 2006 1:29 PM by monkeyden

    Data not getting refreshed, how to disable cache?

    sjmenden

      I am wondering how I disable cache on a per Query basis to ensure the latest data?

      In my code I am select a list of jobs to be displayed in the view. The status of the jobs gets updated frequently, however the changes are not being shown in the view. In the output of jboss, I do get the sql being generated, so I know a database call is happening, I am assuming the data being returned is cached data.

      How Do I indicate to the entity manager NOT to cache this data, or to force a fresh retrieval?

      ...
      
       Map parameters = new HashMap();
       StringBuffer queryString = new StringBuffer();
       queryString.append("from Job");
       Query query = em.createQuery(queryString.toString());
       jobs = (List<Job>) query.getResultList();
      
      ...
      



      Thanks.

        • 1. Re: Data not getting refreshed, how to disable cache?
          sjmenden

          I also tried doing this:

          query.setHint("org.hibernate.cacheable", new Boolean(false));
          query.setHint("org.hibernate.cacheMode", CacheMode.IGNORE);
          


          But I am still getting stale data, the only way to get the new data is to redeploy the webapp.

          Please help.

          • 2. Re: Data not getting refreshed, how to disable cache?
            sjmenden

            I even disabled second level cache to no avail? I am still getting stale data. Mysql command line is still reporting something different than what I am seeing in my view.

            <persistence>
             <persistence-unit name="entityManager">
             <provider>org.hibernate.ejb.HibernatePersistence</provider>
             <jta-data-source>java:/testDatasource</jta-data-source>
             <properties>
             <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
             <property name="hibernate.show_sql" value="true"/>
             <property name="hibernate.format_sql" value="true" />
             <property name="hibernate.cache.use_second_level_cache" value="false" />
             <property name="jboss.entity.manager.factory.jndi.name" value="java:/testEntityManagerFactory"/>
             </properties>
            </persistence-unit>
            </persistence>
            



            Help is greatly appreciated.


            • 3. Re: Data not getting refreshed, how to disable cache?
              monkeyden

              IIRC, the second level cache is off by default. Also, I found this blog entry regarding Hibernate/EJB3 Tuning on the JBoss blog:
              http://jboss.org/jbossBlog/blog/?month=1&day=23&year=2006

              Here is a snippet:

              Note that the default flush mode (auto) in Hibernate flushes data whenever a query is executed or whenever a transaction is committed.

              So configuring none of this should give you the desired result.