3 Replies Latest reply on Nov 13, 2009 7:05 AM by email2liyang

    Seam cache provider with ehcache null

    cateno

      Hi every one,


      I'm trying to configure seam/ehcache following the tutorial from jboss page:


      http://docs.jboss.org/seam/2.1.2/reference/en-US/html/cache.html


      I put the ehcache.1.2.3.jar in project.ear/lib and injected CacheProvider as especified, but the CacheProvider always return null. The documentation doesn't show any aditional configuration for ehcache, just for jboss cache.


      I am probably doing something wrong, it's impossible be so easy :).


      besides put the jar in /lib, i created the following seam component to test:



      @Scope(ScopeType.SESSION)
      @Name("cacheBean")
      public class CacheSeamBean implements java.io.Serializable {
      
       @In(required=false, create=true) 
       private EntityManager em;
      
       @Logger 
       private Log log;
      
       @In
       private Events events;
      
       @In CacheProvider cacheProvider;
      
       Boolean blLoaded = Boolean.FALSE;
      
       @Create
       public void buscar() {
      
        if (!blLoaded){
         List<Parametro> lstParametro = em.createQuery("select p from Parametro p").getResultList();
         for (Parametro parametro : lstParametro){
          cacheProvider.put(parametro.getCodigo(), parametro.getValor());
         }
         blLoaded= Boolean.TRUE;
        }
       }
      }





      Thanks

        • 1. Re: Seam cache provider with ehcache null
          christian.bauer

          It's not that easy, the JBoss Cache provider is hardcoded last time I checked. This website (/examples/wiki) uses EHCache though and you can look at the code to see how that was done.


          Be aware that it's also using the same EHCache instance (with different regions) for Hibernate second-level data caching and HTML page fragment caching. That particular setup depends on the deployment order of persistence unit and Seam, which changed in JBoss 5.x. In other words: If you want to also use EHCache for both and copy the setup 1:1 from the example code, use JBoss 4.2.x.

          • 2. Re: Seam cache provider with ehcache null
            christian.bauer

            Oh, and it looks like what you are trying to do in your code example is not a good idea and you probably don't know much about data caching in Hibernate. Read up on that first before you do anything else.

            • 3. Re: Seam cache provider with ehcache null
              email2liyang
              <components
                          xmlns:cache="http://jboss.com/products/seam/cache"
                          xsi:schemaLocation=
                                  "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd
                          http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd
                          http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd
                          http://jboss.com/products/seam/navigation http://jboss.com/products/seam/navigation-2.0.xsd
                          http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                          http://jboss.com/products/seam/framework http://jboss.com/products/seam/framework-2.0.xsd
                          http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd
                          http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.1.xsd
                          http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.1.xsd">
                 <cache:eh-cache-provider/>
              </components>

              I add the <cache:eh-cache-provider> in components.xml, and put ehcache.jar into lib dir, the  it works