[jboss-jira] [JBoss JIRA] (HIBERNATE-134) Infinispan custom cache command factory not installed error during app deployment

Loïc Ledoyen (JIRA) issues at jboss.org
Fri Jul 25 11:21:37 EDT 2014


    [ https://issues.jboss.org/browse/HIBERNATE-134?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12988068#comment-12988068 ] 

Loïc Ledoyen commented on HIBERNATE-134:
----------------------------------------

I faced the same issue, solving it by using a custom factory, here is the code I used :
{code:title=persistence.xml|borderStyle=solid}
...
<property name="hibernate.cache.region.factory_class" value="org.jboss.as.jpa.hibernate4.infinispan.JndiInfinispanRegionFactory" />
...
{code}

{code:title=JndiInfinispanRegionFactory.java|borderStyle=solid}
package org.jboss.as.jpa.hibernate4.infinispan;

import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.hibernate.cache.CacheException;
import org.hibernate.cache.infinispan.util.CacheCommandFactory;
import org.infinispan.AdvancedCache;
import org.infinispan.commands.module.ModuleCommandFactory;
import org.infinispan.factories.GlobalComponentRegistry;
import org.infinispan.manager.EmbeddedCacheManager;

/**
 * Put in modules/org/jboss/as/jpa/hibernate/4
 * Takes advantages of the classic {@link org.hibernate.cache.infinispan.JndiInfinispanRegionFactory, but adding the CacheCommandFactory to solve classloading issue HIBERNATE-134
 */
public class JndiInfinispanRegionFactory extends org.hibernate.cache.infinispan.JndiInfinispanRegionFactory {

    private static final long serialVersionUID = -3849525520794104001L;

    public JndiInfinispanRegionFactory() {
		super();
    }

    public JndiInfinispanRegionFactory(Properties props) {
		super(props);
    }

    @Override
    protected EmbeddedCacheManager createCacheManager(Properties properties) throws CacheException {
		EmbeddedCacheManager manager = super.createCacheManager(properties);

		CacheCommandFactory ccf = new CacheCommandFactory();
		// ccf.setRegionFactory(this);
		for (String cacheName : manager.getCacheNames()) {
			GlobalComponentRegistry globalCr = manager.getCache(cacheName).getAdvancedCache().getComponentRegistry().getGlobalComponentRegistry();
			Map<Byte, ModuleCommandFactory> factories = (Map<Byte, ModuleCommandFactory>) globalCr.getComponent("org.infinispan.modules.command.factories");
			if (factories == null || factories.size() == 0) {
				factories = new HashMap<Byte, ModuleCommandFactory>();
				factories.put((byte) 'a', ccf);
				globalCr.registerComponent(factories, "org.infinispan.modules.command.factories");
			}
		}
		return manager;
    }

    @SuppressWarnings("rawtypes")
    @Override
    protected AdvancedCache createCacheWrapper(AdvancedCache cache) {
		PrivilegedAction<ClassLoader> action = new PrivilegedAction<ClassLoader>() {
			public ClassLoader run() {
				return Thread.currentThread().getContextClassLoader();
			}
		};
		return cache.with(AccessController.doPrivileged(action));
    }
}
{code}

Then I packaged this class in some jar and added it to the module *org/jboss/as/jpa/hibernate/4*

Hope this will help.

> Infinispan custom cache command factory not installed error during app deployment
> ---------------------------------------------------------------------------------
>
>                 Key: HIBERNATE-134
>                 URL: https://issues.jboss.org/browse/HIBERNATE-134
>             Project: Hibernate Integration
>          Issue Type: Bug
>      Security Level: Public(Everyone can see) 
>         Environment: Ubuntu 12.04, JBoss AS 7.1.2, Hibernate 4.1.2, Infinispan 5.1.4
>            Reporter: Dmitry Chuiko
>            Assignee: Steve Ebersole
>
> We use Infinispan as 2LC for Hibernate in a clustered configuration under JBoss 7. So {{persistence.xml}} contains the following line: {code:xml}<property name="hibernate.cache.region.factory_class" value="org.hibernate.cache.infinispan.InfinispanRegionFactory"/>{code}. The following error occurs during app deployment:  
> {noformat}12:04:52,859 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-14) MSC00001: Failed to start service jboss.persistenceunit."MOYsklad.ear/sklad-base.jar#MOYsklad": org.jboss.msc.service.StartException in service jboss.persistenceunit."MOYsklad.ear/sklad-base.jar#MOYsklad": Failed to start service
> 	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
> 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_05]
> 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_05]
> 	at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_05]
> Caused by: javax.persistence.PersistenceException: [PersistenceUnit: MOYsklad] Unable to build EntityManagerFactory
> 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:915)
> 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:890)
> 	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74)
> 	at org.hibernate.ejb.HibernatePersistenceLognex.createContainerEntityManagerFactory(HibernatePersistenceLognex.java:16)
> 	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.createContainerEntityManagerFactory(PersistenceUnitServiceImpl.java:162)
> 	at org.jboss.as.jpa.service.PersistenceUnitServiceImpl.start(PersistenceUnitServiceImpl.java:85)
> 	at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
> 	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
> 	... 3 more
> Caused by: org.hibernate.cache.CacheException: Infinispan custom cache command factory not installed (possibly because the classloader where Infinispan lives couldn't find the Hibernate Infinispan cache provider)
> 	at org.hibernate.cache.infinispan.InfinispanRegionFactory.getCacheCommandFactory(InfinispanRegionFactory.java:500)
> 	at org.hibernate.cache.infinispan.InfinispanRegionFactory.startRegion(InfinispanRegionFactory.java:379)
> 	at org.hibernate.cache.infinispan.InfinispanRegionFactory.buildEntityRegion(InfinispanRegionFactory.java:212)
> 	at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:347)
> 	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1741)
> 	at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:93)
> 	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:905)
> 	... 10 more
> {noformat}
> This issue takes place because context {{ClassLoader}} is substituted in {{org.hibernate.ejb.Ejb3Configuration#configure}}. So Infinispan can not find {{org.infinispan.commands.module.ModuleCommandExtensions}} realization from {{hibernate-infinispan}} module in {{org.infinispan.util.ModuleProperties#loadModuleCommandHandlers}} method.



--
This message was sent by Atlassian JIRA
(v6.2.6#6264)



More information about the jboss-jira mailing list