6 Replies Latest reply on Oct 16, 2012 2:20 AM by Talha Ahmed Khan

    Not able to connect to Remote DataSource via JNDI while upgrading to AS7 and Hibernate 4

    Talha Ahmed Khan Newbie

      Hi,

       

      We are in a process of upgrading our servers from Jboss 5.1 to Jboss 7.1 Final. But not all the servers will be moving to the new Technology at once.

      I am upgrading the first server on Hibernate 4.0 and Jboss 7.1. But was not been able to connect to the Datasource located on the Other Jboss Server (5.1) via JNDI.

      All other legacy server are runing as usuall.

      Data Source (*-ds.xml) (on legacy Jboss 5.1 Server. All the servers connected to this server for DataSource.)

      <?xml version="1.0" encoding="UTF-8"?>
      <datasources>
       
      <local-tx-datasource>
         
      <jndi-name>jdbc/wc-mysql</jndi-name>

         
      <connection-url>jdbc:mysql://XXX:3306/wellclub</connection-url>
         
      <driver-class>com.mysql.jdbc.Driver</driver-class>
         
      <user-name>myclub</user-name>
         
      <password>myclub</password>

         
      <exception-sorter-class-name>
                org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter
         
      </exception-sorter-class-name>

         
      <!-- The minimum connections in a pool/sub-pool.
               Pools are lazily constructed on first use -->

         
      <min-pool-size>50</min-pool-size>
         
      <!-- The maximum connections in a pool/sub-pool -->
         
      <max-pool-size>200</max-pool-size>
         
      <!-- setting java context as Global so outsider can also use it. -->
         
      <use-java-context>false</use-java-context>
         
      <metadata>
            
      <type-mapping>mySQL</type-mapping>
         
      </metadata>
       
      </local-tx-datasource>
      </datasources>

      hibernate.cfg.xml

       

      <hibernate-configuration>
         
      <session-factory>
             
      <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>

             
      <property name="hibernate.connection.datasource">jdbc/wc-mysql</property>
             
      <property name="hibernate.jndi.url">jnp://jndi.wellclub.me:1099</property>
             
      <property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
             
      <property name="hibernate.jta.UserTransaction">UserTransaction</property>

             
      <property name="hibernate.show_sql">true</property>
             
      <property name="hibernate.current_session_context_class">jta</property>
             
      <property name="hibernate.transaction.manager_lookup_class">org.hibernate.transaction.JBossTransactionManagerLookup</property>
         
      </session-factory>
      </hibernate-configuration>

       

      And in Hibernate Utility class I am initiating the SessionFactory as

       

      Configuration configuration = new Configuration().configure();

      // Add all the Annotated classes here...

      ServiceRegistryBuilder builder = new ServiceRegistryBuilder();
      builder
      .applySettings(configuration.getProperties());
      serviceRegistry
      = builder.buildServiceRegistry();

      sessionFactory
      = configuration.buildSessionFactory(serviceRegistry);
      <== Error

       

      Exception

       

      03:28:01,820 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/core]] (MSC service thread 1-2) Exception sending context initialized event to listener instance of class com.wellclub.service.WCStartupService: org.hibernate.service.jndi.JndiException: Unable to lookup JNDI name [jdbc/wc-mysql]
          at org
      .hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:68) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl.configure(DatasourceConnectionProviderImpl.java:116) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:223) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:89) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.service.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:75) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:159) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:131) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:71) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2273) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.cfg.Configuration.buildSettings(Configuration.java:2269) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at org
      .hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1738) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
          at com
      .wellclub.model.util.ParentHibernateUtil.initiateSessionFactory(ParentHibernateUtil.java:131) [wc-model-2.3.0.jar:]
          at com
      .wellclub.model.util.HibernateUtil.initiateSessionFactory(HibernateUtil.java:32) [classes:]
          at com
      .wellclub.service.WCStartupService.contextInitialized(WCStartupService.java:44) [classes:]
          at org
      .apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
          at org
      .apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
          at org
      .jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
          at org
      .jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
          at org
      .jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
          at java
      .util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_26]
          at java
      .util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_26]
          at java
      .lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_26]
      Caused by: javax.naming.NameNotFoundException: jdbc/wc-mysql -- service jboss.naming.context.java.jdbc.wc-mysql
          at org
      .jboss.as.naming.ServiceBasedNamingStore.lookup(ServiceBasedNamingStore.java:97)
          at org
      .jboss.as.naming.NamingContext.lookup(NamingContext.java:178)
          at org
      .jboss.as.naming.InitialContext.lookup(InitialContext.java:113)
          at javax
      .naming.InitialContext.lookup(InitialContext.java:396) [rt.jar:1.6.0_26]
          at org
      .hibernate.service.jndi.internal.JndiServiceImpl.locate(JndiServiceImpl.java:65) [hibernate-core-4.1.1.Final.jar:4.1.1.Final]
         
      ... 24 more

       

      Please tell me what I am missing. If I am not doing it the correct way please I would like a guidance as well.

      Thanks.

      Talha Ahmed Khan