8 Replies Latest reply on Jul 9, 2010 6:15 PM by Greg Gilles

    Jboss Cache configuration with Seam 2.2 and Jboss 5.1

    Raphaël M. Newbie


      I'm trying to configure JBossCache to run on JBoss 5.1 with Seam 2.2.
      I have checked the documentation, and the examples in seam package but its seems that nothing happens with my configuration...

      So i have had usefull jar in my ear lib: jboss-cache.jar, and jgroups.jar (jar i have found in the seam distribution)
      i have created a treecache.xml with the same file i found in the seam distribution :

      <classpath codebase=".." archives="jbosscache.jar, jgroups.jar"/>

      and referenced it in the componenent.xml :

      <cache:jboss-cache2-provider configuration="META-INF/treecache.xml" />

      so i have this trace :

      11:12:44,679 INFO  [SettingsFactory] JPA-QL strict compliance: enabled
      11:12:44,679 INFO  [SettingsFactory] Second-level cache: enabled
      11:12:44,679 INFO  [SettingsFactory] Query cache: enabled
      11:12:44,679 INFO  [SettingsFactory] Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
      11:12:44,680 INFO  [RegionFactoryCacheProviderBridge] Cache provider: org.hibernate.cache.HashtableCacheProvider
      11:12:44,680 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
      11:12:44,680 INFO  [SettingsFactory] Cache region prefix: persistence.unit:unitName=test-ear.ear/test-ejb.jar#test
      11:12:44,680 INFO  [SettingsFactory] Structured second-level cache entries: disabled
      11:12:44,680 INFO  [SettingsFactory] Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
      11:12:44,681 INFO  [SettingsFactory] Echoing all SQL to stdout
      11:12:44,681 INFO  [SettingsFactory] Statistics: disabled
      11:12:44,681 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
      11:12:44,681 INFO  [SettingsFactory] Default entity-mode: pojo
      11:12:44,681 INFO  [SettingsFactory] Named query checking : enabled
      11:12:44,729 INFO  [Version] Hibernate Search 3.0.1.SNAPSHOT-20080202
      11:12:44,935 INFO  [SessionFactoryImpl] building session factory
      11:12:44,970 WARN  [EntityRegionAdapter] read-only cache configured for mutable entity [persistence.unit:unitName=test-ear.ear/test-ejb.jar#test.com.entity.seed.TypeSeed]

      But when i tried to do in a EBJ a injection like that :

      @In JbossCache2Provider cacheProvider;

      the component can't be created...

      So in examples its seems that we have nothing to do in the persistence.xml but i find on some documentation where persistence.xml should look like that :

      <property name="hibernate.cache.use_second_level_cache" value="true" />
      <property name="hibernate.cache.use_query_cache" value="true" />
      <property name="hibernate.cache.region.jbc2.query.localonly" value="true" />
      <property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory" />
      <property name="hibernate.cache.use_query_cache" value="true" />

      But this configuration file doesn't work because of a classpath problem :
      Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.jbc2.MultiplexedJBossCacheRegionFactory

      So i have some questions:

      Should the jar be in the jboss lib/ too? Are they too old (jboss cache 1.4) but then where can i find jbosscache 2.x or more ? jbosscache and jbosscache-core are same libs?
      In the second case persistence.xml file with some new properties add, why the jar jboss-cache.jar, and jgroups.jar are not add in my classpath?

      Have you some lead for me?

        • 1. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
          Brett Cave Newbie

          I have similar issues, with a migration from JB AS 4.2.2  / Seam 2.1 with JBoss Cache 1.4.1.SP9 migrating to JBossAS 5.1.0 and Seam 2.2.0.

          Some things I have found so far are as follows.

          From the reference manual included with seam 2.2.0:

          The built-in cacheProvider component manages an instance of:
          JBoss Cache 1.x (suitable for use in JBoss 4.2.x or later and other containers)
          JBoss Cache 2.x (suitable for use in JBoss 5.x and other containers)

          Seam 2.2.0 comes with jboss-cache.jar, which is 1.4.1, but also includes jbosscache-core.jar, which is JBCache 2. So I assume that the cache should be JBCache 2.

          JBoss Cache 2 (and 3) has significant structural changes - most relevant for this is that Cache cannot be instantiated directly like old TreeCache could (TreeCache is gone and replaced with Cache). An instance is created by CacheFactory().createCache();

          This would require relevant changes to be made to the old treecache.xml config file (which would now be innappropriately named).

          Perhaps it would be better to programmatically create the cache via the API, rather than xml-configuration, even though the docs say that you should create an xml config file.

          From the web app (WAR) file, configuration for the cache provider now uses cache:jboss-cache2-provider instead of cache:jboss-cache-provider.

          Been battling with this for a few days, so will post an update when / if i make some progress.

          • 2. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
            jboss_user jboss_user Newbie
            This is what I did to get jbosscache 2.2, seam 2.2 and jboss 5.1 to work together.
            1. downloaded jbosscache220 and went to this dir: jbosscache-core-2.2.0.GA/etc/META-INF
            2. copied the local-cache-service.xml to my project's META-INF/ and called it cache-configuration.xml
            3. had to add this to my build.xml so the file got copied in ear..
               <fileset id="ear.resources" dir="${resources.dir}">
                 <include name="META-INF/cache-configuration.xml" />
            4. in the components.xml file I added this: xmlns:cache="http://jboss.com/products/seam/cache"
               at the top, with the other urls like it.
            5. same file, added this: http://jboss.com/products/seam/cache http://jboss.com/products/seam/cache-2.2.xsd (also with the other urls like it)
            6. added this line: <cache:jboss-cache2-provider  name="myCache" auto-create="true" configuration="META-INF/cache-configuration.xml" />
            7. copied jbosscache-core-2.2.0.GA/jbosscache-core.jar to my projects lib/ dir
            8. copied jbosscache-core-2.2.0.GA/lib/compile/jgroups.jar to my projects lib/ dir
            9. added this to my build.xml file:
                <fileset id="ear.lib.extras" dir="${basedir}/lib">
                       <include name="jbosscache-core.jar" />
                       <include name="jgroups.jar" />
            10. to get the cache I put this in my class:
                protected JbossCache2Provider cacheProvider;
            11. I was getting null before for cacheProvider, now I'm not getting that error.
            12. and this tells me the version I'm running: System.out.println("version: " + org.jboss.cache.Version.printVersion());

            Hopefully that's useful to folks. It took some trial and error and help to get this far. So writing this up in hopes that it will make things easier for someone else...

            • 3. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
              Raphaël M. Newbie

              ok thx!

              i have configured a EHCache but i'm still interrest in understanding this!

              and what about the persistence.xml file? there is no need to configure second level caching and region? everything about this configuration is done in the component.xml with the use of cache:jboss-cache2-provider ...  mark and its file config?

              • 4. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
                Jeff Headley Newbie

                I too am curious about configuring the second level hibernate cache in persistence.xml on JBoss 5.1. If you look in <jboss_home>/client/lib/hibernate-core.jar, the cache provider classes appear to have been stripped out for some reason. The only one in there appears to be org.hibernate.cache.HashtableCacheProvider. The others such as those mentioned in Hibernate's documentation do not exist in that jar.

                If you read the JBoss Wiki page about setting up a second level cache in JBoss 5, it mentions the class org.hibernate.cache.jbc2.JndiMultiplexedJBossCacheRegionFactory. As far as I can tell, that class is only found in <jboss_home>/server/all/lib/hibernate-jbosscache2.jar. So to do second level caching in JBoss 5.1 you have to run under the all configuration and not default, Is that correct?

                • 5. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
                  willie slepecki Newbie

                  i followed the instructions for getting jbosscache 2.2.2 above.  its officially running.  but when i try to use the


                  tag i get an exception

                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:277)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
                       at org.jboss.seam.web.RewriteFilter.doFilter(RewriteFilter.java:63)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:42)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
                       at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
                       at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
                       at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
                       at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
                       at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
                       at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
                       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
                       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
                       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                       at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
                       at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:433)
                       at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
                       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
                       at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
                       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
                       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                       at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
                       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
                       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
                       at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
                       at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                       at java.lang.Thread.run(Thread.java:619)
                  Caused by: java.lang.NullPointerException
                       at org.jboss.seam.ui.renderkit.CacheRendererBase.doEncodeChildren(CacheRendererBase.java:38)
                       at org.jboss.seam.ui.util.cdk.RendererBase.encodeChildren(RendererBase.java:92)
                       at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:837)
                       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:930)
                       at javax.faces.component.UIComponent.encodeAll(UIComponent.java:933)
                       at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
                       at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
                       at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
                       at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:110)
                       at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:100)
                       at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
                       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
                       ... 45 more

                  should this work or am i trying to do two different things.

                  • 6. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
                    slawek t Novice

                    I'm facing the same NPE problem with <s:cache> following Pablo's instruction.

                    • 7. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
                      Earnest Dyke Novice

                      For those interested, I was trying to inject a reference to a cache into a Seam component and it was consistently null. I did the following to resolve it:

                      1. I was running my JBoss 5.1 server with a copy of default config NOT all. I copied jbosscache-core.jar, jbosscache-pojo.jar and jgroups.jar from the all config to the lib directory of myconfig.
                      2. I copied replSync-service.xml from all/deploy to myconfig/deploy.

                      When I restarted my app my cacheProvider was populated.


                      • 8. Re: Jboss Cache configuration with Seam 2.2 and Jboss 5.1
                        Greg Gilles Newbie
                        I got <s:cache> working without any real problems as follows:

                        - SEAM jboss-seam-2.2.1.CR1
                        - JBOSS 5.0.1 GA
                        - JBossCache 1.4.1.SP9
                        - JGroups 2.4.1
                        - JBOSSAOP 1.5.0
                        - Eclipse
                        - Deployed my application using a WAR file to the "default" JBOSS Server

                        Why these versions?
                        - These are the versions specified in the "Seam Reference Documentation" PDF file on page 420.  When reading the reference documentation, it wasn't clear if version 2.2 supported the POJO cache in SEAM which is required for <s:cache>, so I used version 1.4.1, but this version is pretty old.

                        Other versions?
                        - The seam "blog" example uses an EAR file that contains cache-2.2 and uses <s:cache>, so clearly version 2.2 also works.

                        - I just followed the directions in "Seam Reference Documentation".
                        - The key thing to make sure is that your build.xml includes <include name="META-INF/treecache.xml" /> so that this file is copied.
                        - Also make sure and that your deployed-jars.list contains references to the required JARS so they get copied when you build.
                        - Then, after you build, check to make sure that treecache.xml and your JARS were deployed in your WAR directory (or EAR if that's what you're using).