13 Replies Latest reply on Dec 20, 2012 4:37 PM by Nico Nico

    Workable configuration for Spring 3.1 + native hibernate 4.1.7 on Jboss 7.1.3.Final with more than one cluster

    Maksym Gryevtsov Newbie

      Hi,

       

      I'm trying without success to find a workable solution. Read through all available documentation and forums posts. Different options brought different problems:

      • Option 1: Native local Hibernate + local ECache. All spring & hibernate jar are in WAR lib. HIbernate uses ecache as 2LC. It works fine as long as you have one JBoss 7 cluster on the network. If you try to deploy application across a few "full-ha" clusters (the same JBoss domain in our case), each node starts generating errors in the log like:

      14:37:06,617 WARN  [org.infinispan.remoting.transport.jgroups.CommandAwareRpcDispatcher] (Incoming-2,null) Problems unmarshalling remote command from byte buffer: java.lang.ClassCastException: org.infinispan.context.Flag cannot be cast to java.lang.String

          at org.jboss.marshalling.ModularClassResolver.resolveClass(ModularClassResolver.java:99)

          at org.jboss.marshalling.river.RiverUnmarshaller.doReadClassDescriptor(RiverUnmarshaller.java:952)

          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:667)

          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

          at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)

          at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readParameters(ReplicableCommandExternalizer.java:119)

          at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readObject(ReplicableCommandExternalizer.java:107)

          at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readObject(ReplicableCommandExternalizer.java:58)

          at org.infinispan.marshall.jboss.ExternalizerTable$ExternalizerAdapter.readObject(ExternalizerTable.java:395)

          at org.infinispan.marshall.jboss.ExternalizerTable.readObject(ExternalizerTable.java:224)

          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:351)

          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

          at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)

          at org.infinispan.marshall.exts.ReplicableCommandExternalizer.readParameters(ReplicableCommandExternalizer.java:119)

          at org.infinispan.marshall.exts.CacheRpcCommandExternalizer.readObject(CacheRpcCommandExternalizer.java:162)

          at org.infinispan.marshall.exts.CacheRpcCommandExternalizer.readObject(CacheRpcCommandExternalizer.java:66)

          at org.infinispan.marshall.jboss.ExternalizerTable$ExternalizerAdapter.readObject(ExternalizerTable.java:395)

          at org.infinispan.marshall.jboss.ExternalizerTable.readObject(ExternalizerTable.java:224)

          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:351)

          at org.jboss.marshalling.river.RiverUnmarshaller.doReadObject(RiverUnmarshaller.java:209)

          at org.jboss.marshalling.AbstractObjectInput.readObject(AbstractObjectInput.java:37)

          at org.infinispan.marshall.jboss.AbstractJBossMarshaller.objectFromObjectStream(AbstractJBossMarshaller.java:163)

          at org.infinispan.marshall.VersionAwareMarshaller.objectFromByteBuffer(VersionAwareMarshaller.java:114)

          at org.infinispan.marshall.AbstractDelegatingMarshaller.objectFromByteBuffer(AbstractDelegatingMarshaller.java:104)

          at org.infinispan.remoting.transport.jgroups.MarshallerAdapter.objectFromBuffer(MarshallerAdapter.java:50)

          at org.infinispan.remoting.transport.jgroups.CommandAwareRpcDispatcher.handle(CommandAwareRpcDispatcher.java:200)

          at org.jgroups.blocks.RequestCorrelator.handleRequest(RequestCorrelator.java:459)

          at org.jgroups.blocks.RequestCorrelator.receiveMessage(RequestCorrelator.java:366)

          at org.jgroups.blocks.RequestCorrelator.receive(RequestCorrelator.java:238)

          at org.jgroups.blocks.MessageDispatcher$ProtocolAdapter.up(MessageDispatcher.java:602)

          at org.jgroups.blocks.mux.MuxUpHandler.up(MuxUpHandler.java:130)

          at org.jgroups.JChannel.up(JChannel.java:716)

          at org.jgroups.stack.ProtocolStack.up(ProtocolStack.java:1026)

          at org.jgroups.protocols.RSVP.up(RSVP.java:188)

          at org.jgroups.protocols.FRAG2.up(FRAG2.java:181)

          at org.jgroups.protocols.FlowControl.up(FlowControl.java:400)

          at org.jgroups.protocols.FlowControl.up(FlowControl.java:418)

          at org.jgroups.protocols.pbcast.GMS.up(GMS.java:889)

          at org.jgroups.protocols.pbcast.STABLE.up(STABLE.java:244)

          at org.jgroups.protocols.UNICAST2.up(UNICAST2.java:383)

          at org.jgroups.protocols.pbcast.NAKACK.handleMessage(NAKACK.java:746)

          at org.jgroups.protocols.pbcast.NAKACK.up(NAKACK.java:566)

          at org.jgroups.protocols.BARRIER.up(BARRIER.java:126)

          at org.jgroups.protocols.VERIFY_SUSPECT.up(VERIFY_SUSPECT.java:143)

          at org.jgroups.protocols.FD.up(FD.java:273)

          at org.jgroups.protocols.FD_SOCK.up(FD_SOCK.java:288)

          at org.jgroups.protocols.MERGE2.up(MERGE2.java:205)

          at org.jgroups.protocols.Discovery.up(Discovery.java:359)

          at org.jgroups.stack.Protocol.up(Protocol.java:363)

          at org.jgroups.protocols.TP.passMessageUp(TP.java:1185)

          at org.jgroups.protocols.TP$IncomingPacket.handleMyMessage(TP.java:1733)

          at org.jgroups.protocols.TP$IncomingPacket.run(TP.java:1715)

          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_07]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_07]

          at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_07]

       

           So it seems I'm forced to use infinispan as 2LC, so... Any idea how to eliminate that sporadic error?

       

      • Option 2: Native local Hibernate + shareable infinispan Add dependency to JBoss 7 org.infinispan, org.javassist modules, remove correspondent local jars, set recommended hibernate properties: hibernate.cache.region.factory_class=org.hibernate.cache.infinispan.JndiInfinispanRegionFactory & hibernate.cache.infinispan.cachemanager=java:jboss/infinispan/container/hibernate, set startup to EAGER for hibernate cache. Now I'm getting these error:

      Caused by: java.lang.ClassCastException: org.hibernate.cache.infinispan.util.CacheCommandInitializer cannot be cast to org.hibernate.cache.infinispan.util.CacheCommandInitializer

          at org.hibernate.cache.infinispan.util.CacheAdapterImpl.<init>(CacheAdapterImpl.java:56) [hibernate-infinispan-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.cache.infinispan.util.CacheAdapterImpl.newInstance(CacheAdapterImpl.java:62) [hibernate-infinispan-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.cache.infinispan.InfinispanRegionFactory.buildEntityRegion(InfinispanRegionFactory.java:210) [hibernate-infinispan-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:344) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1750) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1788) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

       

      I would prefer to use this option. Any ideas how to fix it?

       

      • Option 3: Native shareble Hibernate + shareable infinispan Add dependency to JBoss 7 org.infinispan, org hibernate, org.javassist modules, remove correspondent local jars, set recommended hibernate properties: hibernate.cache.region.factory_class=org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory & hibernate.cache.infinispan.cachemanager=java:jboss/infinispan/container/hibernate. Now I'm

      stuck with bad design for Spring + hibernate 4 implementation where spring libraries must be visible for hibernate module class loader (similar to other posts):

       

      17:38:47,154 ERROR [org.hibernate.internal.SessionFactoryImpl] (MSC service thread 1-1) HHH000302: Unable to construct current session context [org.springframework.orm.hibernate4.SpringSessionContext]: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.springframework.orm.hibernate4.SpringSessionContext]

          at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.internal.SessionFactoryImpl.buildCurrentSessionContext(SessionFactoryImpl.java:1491) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:502) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1746) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784) [hibernate-core-4.1.7.Final.jar:4.1.7.Final]

          at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242) [spring-orm-3.1.2.RELEASE.jar:3.1.2.RELEASE]

       

      Is it dead on arrival option for JBoss 7 or there some ideas how to fix it?

       

      • Option 4: Move spring libs into org.hibernate module - I really do not like it because it might bring an issue with Spring "Glue code and the evil singleton" when a few EAR with the same codebase share its parent context between a few WARs - what we uses. We need local class loaded per EAR for Spring jars.

       

      Thanks,

      Maksym