Configuring Infinispan as L2 Cache, deployment error, jndiName
toriacht Jul 26, 2013 4:16 AMHi,
I'm trying to configure JBoss 7.1 to use Infinispan as L2 Cache as per https://docs.jboss.org/author/display/ISPN/Using+Infinispan+as+JPA-Hibernate+Second+Level+Cache+Provider and http://www.mastertheboss.com/hibernate-cache/using-hibernate-second-level-cache-with-jboss-as-5-6-7
I am running my app in domain mode. When I deploy my app the JNDI lookup for cache manager always fails whether I use
value="java:CacheManager" / or value="java:CacheManager/entity" or value="java:jboss/infinispan/hibernate"/>.
So none of the cache's are available via JNDI so I tried adding the JBoss recommended entity cache (which is the invalidation cache?) to JNDI. I tried it like this (I had to add jboss into teh JNDI name unlike theinstructions as Jboss gave an error unless present)
{code:xml}<cache-container name="hibernate" default-cache="local-query">
<transport lock-timeout="60000"/>
<local-cache name="local-query">
<transaction mode="NONE"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<invalidation-cache name="entity" mode="SYNC" start="EAGER" jndi-name="java:jboss/CacheManager/entity">
<transaction mode="NON_XA"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</invalidation-cache>{code:xml}
but I get an error like this
Caused by: javax.persistence.PersistenceException: Re: Insert Infinispan as Cache Layer above existing Hibernate/MySQL layer Unable to build EntityManagerFactory
Caused by: org.hibernate.cache.CacheException: Unable to start region factory
Caused by: java.lang.ClassCastException: org.jboss.as.clustering.infinispan.DefaultEmbeddedCacheManager$DelegatingCache cannot be cast to org.infinispan.manager.EmbeddedCacheManager
so then i tried to give the CacheContainer a JNDI entry like this:
{code:xml}
<cache-container name="hibernate" default-cache="local-query" jndi-name="java:jboss/CacheManager/entity">
<transport lock-timeout="60000"/>
<local-cache name="local-query">
<transaction mode="NONE"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</local-cache>
<invalidation-cache name="entity" mode="SYNC" start="EAGER" >
<transaction mode="NON_XA"/>
<eviction strategy="LRU" max-entries="10000"/>
<expiration max-idle="100000"/>
</invalidation-cache>{code:xml}
but that gives me
Caused by: java.lang.NullPointerException
at org.hibernate.cache.infinispan.InfinispanRegionFactory.getCache(InfinispanRegionFactory.java:445)
at org.hibernate.cache.infinispan.InfinispanRegionFactory.buildEntityRegion(InfinispanRegionFactory.java:198)
My persistence.xml looks like this
{code:xml}
<persistence-unit name="my-pu" transaction-type="JTA">
{code:xml}
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/mydatasrc</jta-data-source>
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.hbm2ddl.auto" value="update"/>
<property name="hibernate.cache.use_second_level_cache" value="true" />
<property name="hibernate.cache.use_query_cache" value="true" />
<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.JndiInfinispanRegionFactory"/>
<property name="hibernate.cache.infinispan.cachemanager" value="java:CacheManager/entity"/>
<property name="hibernate.cache.region.jbc2.query.localonly" value="true" />
</properties>
</persistence-unit>
SO!... Is my only issue I need to find teh right way to add teh cache to JNDI or I have I bigger configuration issues? Any tips/help very much appreciated.
Best regards
T