2 Replies Latest reply on Oct 25, 2012 10:34 AM by Ernie See

    WebApps sharing JPA entities in one cache

    Ernie See Newbie

      Hi,

       

      i´ve been playing around a while now with trying to deploy several (spring+jpa) web applications in one jboss 7 instance and getting them to share their entities in one infinispan cache.

      Each web application ships some jars with it which contain several (maybe the same) POJO entity classes. Every app has its own persistence and application context.

       

      I read and learned that in such an environment it is not possible to use one single cache instance. Infinispan creates an instance for each web application which makes the cache mechanism useless for my case.

      Now I read about the possibility to use a standalone infinispan cache server and connect it to the JBoss instance as remote cache server. So I tried this configured the JBoss to use a remote-store, started infinispan server and JBoss server but the entities are not cached on the remote server. I also do not see anything from my entities in the jmx console of infinispan.

      Here is my configuration:

       

      {code:xml}

              <subsystem xmlns="urn:jboss:domain:infinispan:1.2" default-cache-container="hibernate">

                  <cache-container name="hibernate" default-cache="entity" start="EAGER">

                      <local-cache name="entity" start="EAGER">

                          <transaction mode="NON_XA"/>

                          <eviction strategy="LRU" max-entries="1000000"/>

                          <expiration max-idle="100000"/>

                          <remote-store socket-timeout="60000">

                              <remote-server outbound-socket-binding="remote-store-hotrod-server"/>

                          </remote-store>

                      </local-cache>

                      <local-cache name="local-query">

                          <transaction mode="NONE"/>

                          <eviction strategy="LRU" max-entries="1000000"/>

                          <expiration max-idle="100000"/>

                      </local-cache>

                      <local-cache name="timestamps">

                          <transaction mode="NONE"/>

                          <eviction strategy="NONE"/>

                      </local-cache>

                  </cache-container>

              </subsystem>

      ...

          <socket-binding-group name="standard-sockets" default-interface="public" port-offset="${jboss.socket.binding.port-offset:0}">

              ...

              <outbound-socket-binding name="remote-store-hotrod-server">

                  <remote-destination host="127.0.0.1" port="11222"/>

              </outbound-socket-binding>

          </socket-binding-group>

      {code}

       

      I´m feeling very uncertain with all this cause I did not find any working example for such a scenario. I even did not find an example or description of the configuration for using remote store, infinispan server and JPA.

      Maybe someone could give me a hint or link to some documentation or could just tell me, that this is not the right way to solve the problem?!?

       

      Thanks in advance,

      Ernie

        • 1. Re: WebApps sharing JPA entities in one cache
          Scott Marlow Master

          How far did you get with sharing the cache locally?  Is there a link with more context about what you discovered (including your Hibernate configuration settings in the persistence unit definitions)?  Setting "hibernate.cache.region_prefix" might help once you are sharing the cache between your applications.

          • 2. Re: WebApps sharing JPA entities in one cache
            Ernie See Newbie

            Hi Scott, here is my Hibernate configuration:

             

            <persistence-unit name="lms"
            transaction-type="JTA">
            <jta-data-source>java:jboss/datasources/lms</jta-data-source>
            <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
            <properties>
            <property name="hibernate.cache.use_second_level_cache" value="true" />
            <property name="hibernate.transaction.factory_class" value="org.hibernate.transaction.CMTTransactionFactory"/>
            <property name="hibernate.cache.infinispan.statistics" value="true"/>
            <property name="hibernate.cache.region.factory_class" value="org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory"/>
            <property name="hibernate.cache.region_prefix" value="lms"/>
            </properties>
            <class>pojo.Artikelstamm</class> ...

            I have 2 web applications which both have a persistence unit containing the configuration listed above + addtional application specific classes.

            After starting JBoss caching for Property instances works but each application caches it on its own.

            If I have a look in JMX-Console (attached) I see that each application got two entries called "Infinispan 2" and "Infinispan 3" for application 1 and "Infinispan 4" and "Infinispan 5" for application 2.

            This looks a bit strange?!?

            If I fetch Artikelstamm entries in application 1 I get such entries listed in the JMX statistics part of Artikelstamm. But application 2 gets nothing of those entries to its cache.