1 Reply Latest reply on Jun 10, 2005 12:36 PM by Emmanuel Bernard

    Caching entities

    manica Newbie

      I have several collections of lookups such as countries and states. I'd like to rely on the second level cache for these; however, I'm noticing that it appears to requery the database everytime instead of using the cache. For example, my Country class has the following annotations:

      @Entity
      @NamedQueries({
       @NamedQuery(name="allCountries", queryString="from Country")
      })
      @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
      


      A session bean service does the following:
      manager.createNamedQuery("allCountries").getResultList();
      


      I understand that the cache is used when retrieving with the primary key of the entity, but I'm issuing a query instead. Is it possible to guarantee a cache hit when running queries?

      Darin