3 Replies Latest reply on Nov 11, 2005 1:28 AM by Gleb Starodubtsev

    EJB3 Second Level Cache

    Andrig Miller Newbie

      I have been trying to get the EJB3 second level cache to start caching my entity beans, but the instructions in the documentation don't seem to work. Here is what I have put in my persistence.xml

      property name="hibernate.cache.provider_class"
       <property name="hibernate.treecache.mbean.object_name"
       <class-cache class="services.entities.Address" usage="transactional"/>
       <class-cache class="services.entities.Customer" usage="transactional"/>
       <class-cache class="services.entities.Inventory" usage="transactional"/>
       <class-cache class="services.entities.Order" usage="transactional"/>
       <collection-cache collection="services.entities.Order.orderLines" usage="transactional"/>
       <class-cache class="services.entities.PricingMethod" usage="transactional"/>
       <class-cache class="services.entities.Product" usage="transactional"/>
       <class-cache class="services.entities.ProductDemand" usage="transactional"/>

      The class-cache lines have the fully qualified object names. I can see in the JBoss log (I am using 4.0.3SP1) that the second level cache is enabled, and I verified that the name of the mbean matches the cluster configuration (EJB3EntityTreeCache), and can see that MBEAN from the JMX console.

      When I execute the application, I am doing a primary key based lookup through the EntityManager.find(xxxx.class, Long.valueOf(xxxx)) method, that do primary key lookups. I understand that this should search the cache by primary key before executing the query, but I get the query everytime, even though I am using the same input parameters each time. I have verified this by watching the monitoring of executed queries from the MySQL Administrator, and by outputing the Hibernate SQL statements to the log.

      I found a topic in this forum that talked about an @Cache annotation, but when I tried to add that, that annotation is not found. I do find an org.hibernate.cache.Cache class in the EJB3 libraries, but even if I manually try to import that class, it is not an annotation, or at least JBoss IDE 1.5RC1 doesn't recognize it as such. The documentation also says nothing about having to use an annotation to get EJB3 entity beans to be stored in the second level cache, only the persistence.xml entries.

      What am I missing?