We are developing an osgi bundle with hibernate, which is deployed on the apache karaf 3.0.2. We have a clustered environment.
And as Level2 caching provider, we were trying to use Hazelcast, But we are not able to get it working.
We are getting "Unable to load com.hazelcast.hibernate.HazelcastCacheRegionFactory " error
Here is what we are doing, if we remove below code, it works fine.
1. In persistence.xml
Code:
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="false" />
<property name="hibernate.cache.use_minimal_puts" value="true" />
<property name="hibernate.cache.region.factory_class" value="com.hazelcast.hibernate.HazelcastCacheRegionFactory" />
3. Installed the following bundles:
Code:
<bundle>mvn:org.hibernate/hibernate-core/4.2.7.Final</bundle>
<bundle>mvn:org.hibernate/hibernate-entitymanager/4.2.7.Final</bundle>
<bundle>mvn:com.hazelcast/hazelcast/3.4</bundle>
<bundle>mvn:com.hazelcast/hazelcast-all/3.2.3</bundle>
<bundle>mvn:com.hazelcast/hazelcast-hibernate4/3.0</bundle>
<bundle>mvn:net.sf.ehcache/ehcache/2.9.0</bundle>
<bundle>mvn:org.hibernate/hibernate-osgi/4.2.2.Final</bundle>
<bundle>mvn:com.hazelcast/hazelcast-hibernate/xxx</bundle>
Are we missing anything? Please help...
This is the error we are getting:
karaf@root()> restart 98
ERROR: Bundle org.apache.aries.jpa.container [72] EventDispatcher: Error during dispatch. (javax.persistence.PersistenceException: [PersistenceUnit: myPU] Unable to b
javax.persistence.PersistenceException: [PersistenceUnit: myPU] Unable to build EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:924)
at org.hibernate.osgi.OsgiPersistenceProvider.createContainerEntityManagerFactory(OsgiPersistenceProvider.java:99)
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.createEntityManagerFactories(EntityManagerFactoryManager.java:329)
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.registerEntityManagerFactories(EntityManagerFactoryManager.java:242)
at org.apache.aries.jpa.container.impl.EntityManagerFactoryManager.bundleStateChange(EntityManagerFactoryManager.java:185)
at org.apache.aries.jpa.container.impl.PersistenceBundleManager.setupManager(PersistenceBundleManager.java:394)
at org.apache.aries.jpa.container.impl.PersistenceBundleManager.addingService(PersistenceBundleManager.java:209)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:932)
at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:864)
at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:256)
at org.osgi.util.tracker.AbstractTracked.track(AbstractTracked.java:229)
at org.osgi.util.tracker.ServiceTracker$Tracked.serviceChanged(ServiceTracker.java:894)
at org.apache.felix.framework.util.EventDispatcher.invokeServiceListenerCallback(EventDispatcher.java:932)
at org.apache.felix.framework.util.EventDispatcher.fireEventImmediately(EventDispatcher.java:793)
at org.apache.felix.framework.util.EventDispatcher.fireServiceEvent(EventDispatcher.java:543)
at org.apache.felix.framework.Felix.fireServiceEvent(Felix.java:4419)
at org.apache.felix.framework.Felix.registerService(Felix.java:3423)
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:346)
at org.apache.felix.framework.BundleContextImpl.registerService(BundleContextImpl.java:320)
at org.hibernate.osgi.HibernateBundleActivator.start(HibernateBundleActivator.java:80)
at org.apache.felix.framework.util.SecureAction.startActivator(SecureAction.java:645)
at org.apache.felix.framework.Felix.activateBundle(Felix.java:2146)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2064)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:955)
at org.apache.felix.framework.BundleImpl.start(BundleImpl.java:942)
at org.apache.karaf.bundle.command.Restart.doExecute(Restart.java:48)
at org.apache.karaf.bundle.command.BundlesCommand.doExecute(BundlesCommand.java:50)
at org.apache.karaf.bundle.command.BundlesCommandWithConfirmation.doExecute(BundlesCommandWithConfirmation.java:41)
at org.apache.karaf.shell.console.AbstractAction.execute(AbstractAction.java:33)
at org.apache.karaf.shell.console.OsgiCommandSupport.execute(OsgiCommandSupport.java:39)
at org.apache.karaf.shell.commands.basic.AbstractCommand.execute(AbstractCommand.java:33)
at Proxy194b83fb_3c13_445e_a0a7_e93cda4c34b5.execute(Unknown Source)
at Proxy194b83fb_3c13_445e_a0a7_e93cda4c34b5.execute(Unknown Source)
at org.apache.felix.gogo.runtime.CommandProxy.execute(CommandProxy.java:78)
at org.apache.felix.gogo.runtime.Closure.executeCmd(Closure.java:477)
at org.apache.felix.gogo.runtime.Closure.executeStatement(Closure.java:403)
at org.apache.felix.gogo.runtime.Pipe.run(Pipe.java:108)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:183)
at org.apache.felix.gogo.runtime.Closure.execute(Closure.java:120)
at org.apache.felix.gogo.runtime.CommandSessionImpl.execute(CommandSessionImpl.java:92)
at org.apache.karaf.shell.console.impl.jline.ConsoleImpl.run(ConsoleImpl.java:203)
at org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1$1.run(LocalConsoleManager.java:115)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.karaf.jaas.modules.JaasHelper.doAs(JaasHelper.java:57)
at org.apache.karaf.shell.console.impl.jline.LocalConsoleManager$2$1.run(LocalConsoleManager.java:108)
Caused by: org.hibernate.HibernateException: could not instantiate RegionFactory [com.hazelcast.hibernate.HazelcastCacheRegionFactory]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:501)
at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:289)
at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2335)
at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2331)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1767)
at org.hibernate.ejb.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:96)
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:914)
... 44 more
Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [com.hazelcast.hibernate.HazelcastCacheRegionFactory]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:149)
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:484)
... 50 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.hazelcast.hibernate.HazelcastCacheRegionFactory
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:296)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:274)
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:146)
... 51 more
karaf@root()>