2 Replies Latest reply on Jun 17, 2014 9:39 AM by Keith Gauntt

    Binding Hibernate Session Factory in JNDI

    Keith Gauntt Newbie

      Hello,

       

      My current hibernate configuration looks like the following:

       

      <session-factory>

       

        <property name="hibernate.connection.datasource">java:jboss/datasources/BtocXADS</property>

        <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>

        <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>

        <property name="hibernate.cache.provider_class">org.hibernate.cache.NoCacheProvider</property>

        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>

        <property name="hibernate.session_factory_name">java:jboss/hibernate/BtocSessionFactory</property>

      ...................

       

      I then have a Spring bean definition that uses a jndi lookup to get the session factory:

      <jee:jndi-lookup id="btocSessionFactory" jndi-name="java:jboss/hibernate/BtocSessionFactory" />

       

      This used to work in older versions of Jboss, but now I'm getting an exception when the Spring configuration is loaded b/c Jboss cannot find the name I specify in JNDI.  Is it still possible to bind the session factory to JNDI in Jboss EAP 6.2?  If so, do I need something defined in standalone-full.xml?  I should add that the Hibernate code was orginally written in Hibernate 3, and I realize I may need to make code changes to get everything working with Hibernate 4, but I'd still like to pull the session factory out of JNDI.

       

      Thanks in advance.....

        • 1. Re: Binding Hibernate Session Factory in JNDI
          jaikiran pai Master

          Keith, please post the entire exception stacktrace? Also, are you sure that the hibernate configuration is being picked up by Spring and the session factory is indeed bound to JNDI?

          • 2. Re: Binding Hibernate Session Factory in JNDI
            Keith Gauntt Newbie

            I apologize for not being clearer in my post.  The session factory is not being bound to JNDI.  I'm not sure why it is not, or what I need to do to get it bound. Older versions of Jboss had a Hibernate service that would load session factories in JNDI based on what was specified in the Hibernate configuration file.  I'm not sure if that service is still present in 6.2 EAP, or if there is something equivalent.  As you can see in the stack trace below( javax.naming.NameNotFoundException), the Spring JNDI lookup on the session factory fails :

             

            ERROR [org.jboss.as.ejb3.invocation] (default-threads - 19) JBAS014134: EJB Invocation failed on component BtocConsumerBean for method public abstract void javax.jms.MessageListener.onMessage(javax.jms.Message): javax.ejb.EJBTransactionRolledbackException: JBAS011048: Failed to construct component instance

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleInCallerTx(CMTTxInterceptor.java:162) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:252) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:341) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:238) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

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

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

              at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

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

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

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

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

              at org.jboss.as.ejb3.component.interceptors.AdditionalSetupInterceptor.processInvocation(AdditionalSetupInterceptor.java:55) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

              at org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription$5$1.processInvocation(MessageDrivenComponentDescription.java:203) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

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

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

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

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

              at org.jboss.as.ee.component.ViewDescription$1.processInvocation(ViewDescription.java:182) [jboss-as-ee-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

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

              at org.jboss.as.ee.component.ProxyInvocationHandler.invoke(ProxyInvocationHandler.java:72) [jboss-as-ee-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at javax.jms.MessageListener$$$view1.onMessage(Unknown Source) [jboss-jms-api_1.1_spec-1.0.1.Final-redhat-2.jar:1.0.1.Final-redhat-2]

              at sun.reflect.GeneratedMethodAccessor27.invoke(Unknown Source) [:1.7.0_55]

              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) [rt.jar:1.7.0_55]

              at java.lang.reflect.Method.invoke(Method.java:606) [rt.jar:1.7.0_55]

              at org.jboss.as.ejb3.inflow.MessageEndpointInvocationHandler.doInvoke(MessageEndpointInvocationHandler.java:140) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.inflow.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:73) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at com.sun.proxy.$Proxy16.onMessage(Unknown Source)

              at com.ibm.mq.connector.inbound.MessageEndpointWrapper.onMessage(MessageEndpointWrapper.java:136)

              at com.ibm.mq.jms.MQSession$FacadeMessageListener.onMessage(MQSession.java:138)

              at com.ibm.msg.client.jms.internal.JmsSessionImpl.run(JmsSessionImpl.java:2677)

              at com.ibm.mq.jms.MQSession.run(MQSession.java:963) [com.ibm.mqjms.jar:6.0.2.5 - j600-205-080922  ]

              at com.ibm.mq.connector.inbound.ASFWorkImpl.doDelivery(ASFWorkImpl.java:102)

              at com.ibm.mq.connector.inbound.AbstractWorkImpl.run(AbstractWorkImpl.java:240)

              at org.jboss.jca.core.workmanager.WorkWrapper.run(WorkWrapper.java:218)

              at org.jboss.threads.SimpleDirectExecutor.execute(SimpleDirectExecutor.java:33)

              at org.jboss.threads.QueueExecutor.runTask(QueueExecutor.java:808)

              at org.jboss.threads.QueueExecutor.access$100(QueueExecutor.java:45)

              at org.jboss.threads.QueueExecutor$Worker.run(QueueExecutor.java:828)

              at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_55]

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

            Caused by: java.lang.IllegalStateException: JBAS011048: Failed to construct component instance

              at org.jboss.as.ee.component.BasicComponent.constructComponentInstance(BasicComponent.java:163) [jboss-as-ee-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

              at org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponent$1.create(MessageDrivenComponent.java:85) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponent$1.create(MessageDrivenComponent.java:82) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

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

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

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

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:250) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              ... 43 more

            Caused by: javax.ejb.EJBException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'consumerEventProcessor' defined in class path resource [applicationContext.xml]: Cannot create inner bean 'com.broadspire.evtcons.common.ConsumerEventProcessorImpl#f42338' of type [com.broadspire.evtcons.common.ConsumerEventProcessorImpl] while setting bean property 'target'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.broadspire.evtcons.common.ConsumerEventProcessorImpl#f42338' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'recordPersister' while setting bean property 'persister'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'recordPersister' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'btocCompositeDao' while setting bean property 'recordDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'btocCompositeDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'endOfDayDao' while setting bean property 'chain' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'endOfDayDao' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'btoc999Home' while setting bean property 'generatedDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'btoc999Home' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'btocSessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'btocSessionFactory': Invocation of init method failed; nested exception is javax.naming.NameNotFoundException: java:hibernate/BtocSessionFactory

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:189) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:274) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.tx.CMTTxInterceptor.requiresNew(CMTTxInterceptor.java:363) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

              at org.jboss.as.ejb3.tx.LifecycleCMTTxInterceptor.processInvocation(LifecycleCMTTxInterceptor.java:66) [jboss-as-ejb3-7.3.0.Final-redhat-14.jar:7.3.0.Final-redhat-14]

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

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

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

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

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

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

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

              ... 51 more