1 Reply Latest reply on Dec 4, 2008 3:54 AM by apdo

    query cache configuration

      I am using jboss 4.2.3 GA

      I want to use EJB3 with caching. I don't plan in the short term to use clustering. Is Jboss cache the most common caching mechanism to be use for EJB3 on Jboss?

      To enable caching on the default configuration, I follow the french instruction provided in at the following location:

      It says to copy the following file from the all configuration to the default configuration:
      jgroup*.jar (most probably useless in my case since I doesn't use clustoring.)

      I have confured ejb-entity-cache-service.xml with LOCAL since I am not using clustering.

      My persistence.xml file look like this:

       <persistence-unit name="securityEJB3">
       <properties >
       <property name="hibernate.hbm2ddl.auto" value="update"/>
       <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
       <property name="hibernate.show_sql" value="true"/>
       <property name="hibernate.cache.use_query_cache" value="true"/>
       <property name="hibernate.cache.provider_class" value="org.jboss.ejb3.entity.TreeCacheProviderHook" />
       <property name="hibernate.treecache.mbean.object_name" value="jboss.cache:service=EJB3EntityTreeCache" />
       </properties >

      According to my test, caching is working well if I find object using the entitymanager .find method and when I find entity children of another entity. I conclude that it is working find since after activating the second level caching I see Hibernate query in my server.log only for the first time I get an entity. The following call to entitymanager.find for the same entity doesn't generate hibernate query in my log.

      However, I think that my configuration didn't enable the query cache since for every execution of the same query using entitymanager.createQuery
      I see the hibernate query in my server.log file.

      Could you please tell me what is missing in my configuration to make the query cache working?

      Thank you,

      An Phong Do

        • 1. Re: query cache configuration

          I found one the following web site:

          that the query must be configure to be cached programatically. According to my testing, it must be done in addition to the configuration in persistence.xml with

          <property name="hibernate.cache.use_query_cache" value="true"/>

           Query accountQuery = em.createQuery("from Account a where a < 50");
           accountQuery.setHint("org.hibernate.cacheable", true);
           List<Account> accounts = accountQuery.getResultList();