3 Replies Latest reply on May 31, 2012 2:35 PM by tdanecito

    How to setup 2nd level cache using only standalone.xml?

    tdanecito

      Hi All,

       

      Is there a way to setup 2nd level cache using just the standalone.xml? I have a small database that is mostly readonly operations and it sounds like 2nd level cache is what I want but I do not want to rebuild my ear and make changes to my code and add a persistence.xml file.

       

      Thanks for the help!

      -Tony

        • 1. Re: How to setup 2nd level cache using only standalone.xml?
          tdanecito

          Hi All,

           

          I ended up adding a persistence.xml file in my EAR under META_INF and inside the xml file specifying my datasources (databases). It seemed to parse ok and and no errors in my server logs but I do not know how to verify the cache is being used yet. I made no change to my EJB code using annotations to specify caching so hope I am ok.

           

          Regards,

          -Tony

          • 2. Re: How to setup 2nd level cache using only standalone.xml?
            smarlow

            You can get the second level cache statistics with the AS/bin/jboss-cli tool.  We probably should describe that in the JPA doc.  The statistics are only available for Hibernate 4 currently.

             

            After I have deployed jboss-javaee6-webapp.war (which already has statistics enabled by default via <property name="hibernate.generate_statistics" value="true"/>),I ran the jboss-cli tool and entered commands:

             

            1. connect – connects to the local as7 instance
            2. cd deployment – changed into deployments (you can enter an 'ls' command to see the deployments)
            3. cd jboss-javaee6-webapp.war – changed into my test app deployment
            4. cd subsystem – a view of the different subsystems are here (try an 'ls' to see them)
            5. cd jpa – change into the 'jpa' subsystem
            6. cd hibernate-persistence-unit – change into the Hibernate JPA persistence unit folder (all persistence units for deployment are here)
            7. cd jboss-javaee6-webapp.war#primary - change into the 'primary' persistence unit folder (using its fully qualified name)
            8. ls – will show basic statistics
            9. :write-attribute(name=enabled,value=true) – will enable statistics for the current persistence unit (false will disable)
            10. cd entity-cache - all entities that are enabled to have a second level cache are here
            11. cd org.jboss.tools.examples.modelMember - change into the 'modelMember' entity folder
            12. :read-resource(include-runtime=true) - show statistics for 'modelMember' entity second level cache
            13. pwd – show the current working directory

             

            You should be able to do the same with your deployment (just remember to use the 'ls' command often to see the choices of what you can 'cd' into.)

            • 3. Re: How to setup 2nd level cache using only standalone.xml?
              tdanecito

              Hi Scott,

               

              Thanks for the info I will look at it tonight and let you know how it works out.

               

              -Tony