Using the same hibernate L2 cache for different web applications using Hazelcast multicast

We used Hazelcast as the Hibernate L2 cache provider for our application with the same DB and deployed as two different web applications.

webApp1.war: using DB1

webApp2.war: using DB1

The hazelcast configuration for both web applications is the same:

        <multicast enabled="true">
            <multicast-group>224.2.2.3</multicast-group>
            <multicast-port>54327</multicast-port>
        </multicast>

      

The group name and password are also the same for both web applications.

Hazelcast adds them to a cluster with different nodes, which also appears in the Hazelcast Control Center.

Hazelcast creates two different Maps for the same DBMS object for these web applications. Thus, for example, if the entity "food" is updated by "webApp1", it will not be reflected in "webApp2".

The control center shows that it has created two different maps for "food", ie. webApp1.war: food and webApp2.war: food

Can you suggest using multicast how to use the same L2 cache for two different web applications on the same cluster.

Edit - 1: Hibernate config - Persistence.xml

  

    <jta-data-source>java:jboss/datasources/mealsDS</jta-data-source>
    <shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>

    <properties>
        <property name="hibernate.connection.pool_size" value="1" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.cache.use_second_level_cache" value="true"/>
        <property name="hibernate.cache.region.factory_class" value="com.hazelcast.hibernate.HazelcastCacheRegionFactory"/>
    </properties>
</persistence-unit>

      

Hazelcast config - Hazelcast.xml (similar to that presented in hazelacast.jar)

<group>
    <name>local</name>
    <password>local-pass</password>
</group>

<management-center enabled="true">http://localhost:8080/mancenter
</management-center>
<network>
    <port auto-increment="true" port-count="100">5701</port>
    <outbound-ports>
        <ports>0</ports>
    </outbound-ports>
    <join>
        <multicast enabled="true">
            <multicast-group>224.2.2.3</multicast-group>
            <multicast-port>54327</multicast-port>
        </multicast>
        <tcp-ip enabled="false">
            <interface>127.0.0.1</interface>
        </tcp-ip>
        <aws enabled="false">
            <access-key>my-access-key</access-key>
            <secret-key>my-secret-key</secret-key>
            <region>us-west-1</region>
            <host-header>ec2.amazonaws.com</host-header>
            <security-group-name>hazelcast-sg</security-group-name>
            <tag-key>type</tag-key>
            <tag-value>hz-nodes</tag-value>
        </aws>
    </join>
    <interfaces enabled="false">
        <interface>10.10.1.*</interface>
    </interfaces>
    <ssl enabled="false" />
    <socket-interceptor enabled="false" />
    <symmetric-encryption enabled="false">
        <algorithm>PBEWithMD5AndDES</algorithm>
        <salt>thesalt</salt>
        <password>thepass</password>
        <iteration-count>19</iteration-count>
    </symmetric-encryption>
</network>
<partition-group enabled="false" />
<executor-service name="default">
    <pool-size>16</pool-size>
    <queue-capacity>0</queue-capacity>
</executor-service>
<queue name="default">
    <max-size>0</max-size>
    <backup-count>1</backup-count>
    <async-backup-count>0</async-backup-count>
    <empty-queue-ttl>-1</empty-queue-ttl>
</queue>
<map name="default">
    <in-memory-format>BINARY</in-memory-format>
    <backup-count>1</backup-count>
    <async-backup-count>0</async-backup-count>
    <time-to-live-seconds>0</time-to-live-seconds>
    <max-idle-seconds>0</max-idle-seconds>
    <eviction-policy>NONE</eviction-policy>
    <max-size policy="PER_NODE">0</max-size>
    <eviction-percentage>25</eviction-percentage>
    <min-eviction-check-millis>100</min-eviction-check-millis>
    <merge-policy>com.hazelcast.map.merge.PutIfAbsentMapMergePolicy
    </merge-policy>
</map>
<multimap name="default">
    <backup-count>1</backup-count>
    <value-collection-type>SET</value-collection-type>
</multimap>
<multimap name="default">
    <backup-count>1</backup-count>
    <value-collection-type>SET</value-collection-type>
</multimap>
<list name="default">
    <backup-count>1</backup-count>
</list>
<set name="default">
    <backup-count>1</backup-count>
</set>
<jobtracker name="default">
    <max-thread-size>0</max-thread-size>
    <queue-size>0</queue-size>
    <retry-count>0</retry-count>
    <chunk-size>1000</chunk-size>
    <communicate-stats>true</communicate-stats>
    <topology-changed-strategy>CANCEL_RUNNING_OPERATION
    </topology-changed-strategy>
</jobtracker>
<semaphore name="default">
    <initial-permits>0</initial-permits>
    <backup-count>1</backup-count>
    <async-backup-count>0</async-backup-count>
</semaphore>
<serialization>
    <portable-version>0</portable-version>
</serialization>
<services enable-defaults="true" />

      

+3


source to share


1 answer


Solved this by setting the property in my persistence.xml

<property name="hibernate.cache.region_prefix" value="myApp"/>

      



if this property is not set, it restricts hibernate to adding the application name to the map created in memory, so there is only one map for both web applications, whether it is used by the same DB or not.

+1


source







All Articles