1 Reply Latest reply on Aug 27, 2012 12:01 PM by Ajay Deshwal

    JBoss AS 7 and Hibernate 4, multi tenancy.

    Ajay Deshwal Newbie

      MyHI,

       

      I'm developing an application that need to support multi tenancy feature and i recently learned that hibernates supports it in versions 4.x.

      To implement it, a developer needs to implement hibernate interfaces to make it aware of tenant identifier and connection provider.

      The application is based on ejb3.1, hibernate 4.1.6.Final and Spring 3.1.2.RELEASE with cache managed by infinispan. The AS version i'm using is 7.1.1.Final.

      The application is an ear enclosing an ejb jar and a war. The hibernate config,model classes and multi tenancy connection provider impl etc all rests inside ejb module.

      After setting it all up,, everything works perfectly if i package hibernate libraries inside ear/lib directory in my deployment. But that is not the way jboss 7 is intended to be used i think i.e. all complex resusable dependecies must be declared as modules. So i installed mentioned version of hibernate as JBoss modules(infact upgraded exisiting hibernate modules). After this change, the application stopped working because hibernate is not able to locate com.myapp.server.saas.MultiTenantConnectionProvider . Following is the exception trace i get:

       

      [org.hibernate.service.jdbc.connections.internal.MultiTenantConnectionProviderInitiator] (EJB default - 1) Unable to locate specified class [com.myapp.server.saas.MultiTenantConnectionProvider]: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [com.myapp.server.saas.MultiTenantConnectionProvider]

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

          at org.hibernate.service.jdbc.connections.internal.MultiTenantConnectionProviderInitiator.initiateService(MultiTenantConnectionProviderInitiator.java:84) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.jdbc.connections.internal.MultiTenantConnectionProviderInitiator.initiateService(MultiTenantConnectionProviderInitiator.java:43) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:69) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:176) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:150) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:228) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:73) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2279) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2275) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

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

          at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1784) [hibernate-core-4.1.6.Final.jar:4.1.6.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]

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

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

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

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

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

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

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

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:93) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_33]

          at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_33]

          at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_33]

          at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_33]

          at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:147) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:110) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:280) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

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

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

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

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

          at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.context.access.ContextSingletonBeanFactoryLocator.initializeDefinition(ContextSingletonBeanFactoryLocator.java:143) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.beans.factory.access.SingletonBeanFactoryLocator.useBeanFactory(SingletonBeanFactoryLocator.java:381) [spring-beans-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactoryReference(SpringBeanAutowiringInterceptor.java:156) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.getBeanFactory(SpringBeanAutowiringInterceptor.java:137) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.doAutowireBean(SpringBeanAutowiringInterceptor.java:117) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at org.springframework.ejb.interceptor.SpringBeanAutowiringInterceptor.autowireBean(SpringBeanAutowiringInterceptor.java:97) [spring-context-3.1.2.RELEASE.jar:3.1.2.RELEASE]

          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_33]

          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_33]

          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_33]

          at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_33]

          at org.jboss.as.ee.component.ManagedReferenceLifecycleMethodInterceptorFactory$ManagedReferenceLifecycleMethodInterceptor.processInvocation(ManagedReferenceLifecycleMethodInterceptorFactory.java:118) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ManagedReferenceInterceptorFactory$ManagedReferenceInterceptor.processInvocation(ManagedReferenceInterceptorFactory.java:95) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.WeavedInterceptor.processInvocation(WeavedInterceptor.java:53) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:161) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ee.component.BasicComponent.createInstance(BasicComponent.java:85) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:66) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.component.stateless.StatelessSessionComponent$1.create(StatelessSessionComponent.java:63) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.pool.AbstractPool.create(AbstractPool.java:60) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.pool.strictmax.StrictMaxPool.get(StrictMaxPool.java:123) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.component.pool.PooledInstanceInterceptor.processInvocation(PooledInstanceInterceptor.java:47) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:228) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:304) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:190) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.remote.EJBRemoteTransactionPropagatingInterceptor.processInvocation(EJBRemoteTransactionPropagatingInterceptor.java:80) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.NamespaceContextInterceptor.processInvocation(NamespaceContextInterceptor.java:50) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:43) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.TCCLInterceptor.processInvocation(TCCLInterceptor.java:45) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:288) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.invocation.ChainedInterceptor.processInvocation(ChainedInterceptor.java:61) [jboss-invocation-1.1.1.Final.jar:1.1.1.Final]

          at org.jboss.as.ee.component.ViewService$View.invoke(ViewService.java:165) [jboss-as-ee-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.invokeMethod(MethodInvocationMessageHandler.java:302) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler.access$200(MethodInvocationMessageHandler.java:64) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at org.jboss.as.ejb3.remote.protocol.versionone.MethodInvocationMessageHandler$1.run(MethodInvocationMessageHandler.java:196) [jboss-as-ejb3-7.1.1.Final.jar:7.1.1.Final]

          at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441) [rt.jar:1.6.0_33]

          at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) [rt.jar:1.6.0_33]

          at java.util.concurrent.FutureTask.run(FutureTask.java:138) [rt.jar:1.6.0_33]

          at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_33]

          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_33]

          at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_33]

          at org.jboss.threads.JBossThread.run(JBossThread.java:122)

      Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.myapp.server.saas.MultiTenantConnectionProvider

          at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99) [hibernate-core-4.1.6.Final.jar:4.1.6.Final]

          at java.lang.ClassLoader.loadClass(ClassLoader.java:306) [rt.jar:1.6.0_33]

          at java.lang.ClassLoader.loadClass(ClassLoader.java:247) [rt.jar:1.6.0_33]

          at java.lang.Class.forName0(Native Method) [rt.jar:1.6.0_33]

          at java.lang.Class.forName(Class.java:247) [rt.jar:1.6.0_33]

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

          ... 128 more

       

       

       

       

      com.myapp.server.saas.MultiTenantConnectionProvider is located inside myear.ear/myejb.jar. The cause of issue in my understanding is that my application classes can access hibernate modules but vice versa is not possible as hibernate module.xml do not specify any dependency of hibernate on my application. So hibernate module class loader won't have sufficient accessibilty to load com.myapp.server.saas.MultiTenantConnectionProvider.

       

      If this is the case, is there any way to overcome this constraint?

       

      Following is my jboss-deployment-structure.xml

       

      <?xml version="1.0" encoding="UTF-8"?>

       

      <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.0"

          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

          xsi:schemaLocation="urn:jboss:deployment-structure:1.0  http://www.jboss.org/schema/jbossas/jboss-deployment-structure-1_0.xsd" >

         

          <deployment>

              <dependencies>

                  <module name="com.mysql" export="true" />

                  <module name="org.hibernate" export="true" />

                  <module name="org.infinispan" export="true" />

                  <module name="org.hibernate.envers" export="true"/>

              </dependencies>

          </deployment>

       

      </jboss-deployment-structure>

       

       

      Thanks!!!

        • 1. Re: JBoss AS 7 and Hibernate 4, multi tenancy.
          Ajay Deshwal Newbie

          I found the issue.

           

          I was using Spring's org.springframework.orm.hibernate4.LocalSessionFactoryBean to inject session factory into application dao layer. Internally it uses Configuration.buildSessionFactory() (a deprecated method) to initialize session factory. Deep into the execution chain, all resource class loaders are set to  ClassLoaderServiceImpl.class.getClassLoader(). I fixed the issue by calling Configuration.buildSessionFactory(serviceRegistry) with my custom serviceRegistry setting all class loaders to null. It enables ClassLoaderServiceImpl to set all classloaders appropriately. To be precise, to fix my issue it sets applicationClassLoader to thread context class loader (Thread.currentThread().getContextClassLoader()).

           

          I implemented the login in my custom session factory bean which extends org.springframework.orm.hibernate4.LocalSessionFactoryBean. Everything is working like a charm now. Following is the impl:

           

           

           

          import java.util.LinkedHashSet;

          import java.util.Properties;

           

          import org.hibernate.SessionFactory;

          import org.hibernate.SessionFactoryObserver;

          import org.hibernate.cfg.Environment;

          import org.hibernate.integrator.internal.IntegratorServiceImpl;

          import org.hibernate.integrator.spi.Integrator;

          import org.hibernate.internal.util.config.ConfigurationHelper;

          import org.hibernate.service.BootstrapServiceRegistry;

          import org.hibernate.service.ServiceRegistry;

          import org.hibernate.service.ServiceRegistryBuilder;

          import org.hibernate.service.classloading.internal.ClassLoaderServiceImpl;

          import org.hibernate.service.internal.BootstrapServiceRegistryImpl;

          import org.hibernate.service.internal.StandardServiceRegistryImpl;

          import org.springframework.orm.hibernate4.LocalSessionFactoryBean;

          import org.springframework.orm.hibernate4.LocalSessionFactoryBuilder;

           

          public class CustomSessionFactoryBean extends LocalSessionFactoryBean {

              private static final LinkedHashSet<Integrator> NO_INTEGRATORS = new LinkedHashSet<Integrator>();

           

             

              private ClassLoader applicationClassLoader;

              private ClassLoader resourcesClassLoader;

              private ClassLoader hibernateClassLoader;

              private ClassLoader environmentClassLoader;

           

              @Override

              @SuppressWarnings("serial")

              protected SessionFactory buildSessionFactory(LocalSessionFactoryBuilder sfb) {

                  Properties properies = sfb.getProperties();

                  Environment.verifyProperties(properies);

                  ConfigurationHelper.resolvePlaceHolders(properies);

                  final ServiceRegistry serviceRegistry = getDefaultServiceRegistry(properies);

                  sfb.setSessionFactoryObserver(new SessionFactoryObserver() {

                      @Override

                      public void sessionFactoryCreated(SessionFactory factory) {

                      }

           

                      @Override

                      public void sessionFactoryClosed(SessionFactory factory) {

                          ((StandardServiceRegistryImpl) serviceRegistry).destroy();

                      }

                  });

                  return sfb.buildSessionFactory(serviceRegistry);

              }

           

              private ServiceRegistry getDefaultServiceRegistry(Properties properies) {

                  final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder(

                          getBootstrapServiceRegistry()).applySettings(properies)

                          .buildServiceRegistry();

           

                  return serviceRegistry;

              }

           

              private BootstrapServiceRegistry getBootstrapServiceRegistry() {

                  final ClassLoaderServiceImpl classLoaderService = new ClassLoaderServiceImpl(

                          applicationClassLoader, resourcesClassLoader,

                          hibernateClassLoader, environmentClassLoader);

           

                  final IntegratorServiceImpl integratorService = new IntegratorServiceImpl(

                          NO_INTEGRATORS, classLoaderService);

           

                  return new BootstrapServiceRegistryImpl(classLoaderService,

                          integratorService);

              }

           

          }