2 Replies Latest reply on Jul 27, 2005 8:38 AM by ads_green

    Jboss 4.0.1, Hibernate 3 and Tomcat 5.5

    ads_green

      Hi all,

      I have an application using the Hibernate 3 persistance framework running in both Tomcat 5.5 and Jboss 4.0.1 environments. To simplify deployment, I'd like to configure the application WAR to use container defined datasources.

      I can get the application working on Tomcat 5.5 or Jboss 4.0.1 but not using the same configuration (which seems to defeat the point of using datasources if I need to change them depending on the platform used!)

      The hibernate.cfg.xml that works with tomcat 5.5 is:
      <hibernate-configuration>
      <session-factory>
      java:comp/env/DB1DS
      org.hibernate.dialect.MySQLDialect
      </session-factory>
      </hibernate-configuration>


      The Tomcat 5.5 global datasource definition is:





      Finally, the WAR's context.xml is:





      However, when deploying what I belive to be the equivlant datasource definition in Jboss 4.0.1 using the file mysql-ds.xml in the deploy directory:


      <local-tx-datasource>
      <jndi-name>comp/env/DB1DS</jndi-name>
      <use-java-context>true</use-java-context>
      <connection-url>jdbc:mysql://localhost:3306/db1?autoReconnect=true</connection-url>
      <driver-class>org.gjt.mm.mysql.Driver</driver-class>
      <user-name>root</user-name>
      root
      </local-tx-datasource>


      This registers a datasource with a JNDI name of java:comp/env/DB1DS but when trying to run the very same WAR file deployed to the JBoss server, it fails with the exception:
      FATAL [DatasourceConnectionProvider] Could not find datasource: comp/env/DB1DS
      javax.naming.NameNotFoundException: comp not bound

      Ive tried various combinations of names and configuations but I can't find a single configuration that works both in Jboss and Tomcat without some kind of alteration.

      Is there the equivilant of the Tomcat context.xml that needs to be configured in order for an application to be able to use the Jboss configured datasource?

      Any help gratefully appreciated!

        • 1. Re: Jboss 4.0.1, Hibernate 3 and Tomcat 5.5
          ads_green

          Sorry - missing some info:

          The Tomcat 5.5 global datasource definition is:






          Finally, the WAR's context.xml is:




          • 2. Re: Jboss 4.0.1, Hibernate 3 and Tomcat 5.5
            ads_green

            The Tomcat 5.5 global datasource definition is:

            <GlobalNamingResources>
             <Resource auth="Container" name="DB1DS" type="javax.sql.DataSource"
             username="root" password="root" driverClassName="org.gjt.mm.mysql.Driver"
             url="jdbc:mysql://localhost:3306/db1?autoReconnect=true"
             factory="org.apache.commons.dbcp.BasicDataSourceFactory"/>
            </GlobalNamingResources>


            Finally, the WAR's context.xml is:
            <Context docBase="..." path="...">
             <ResourceLink global="DB1DS" name="DB1DS" type="javax.sql.DataSource"/>
            </Context>


            However, when deploying what I belive to be the equivlant datasource definition in Jboss 4.0.1 using the file mysql-ds.xml in the deploy directory:

            <datasources>
             <local-tx-datasource>
             <jndi-name>comp/env/DB1DS</jndi-name>
             <use-java-context>true</use-java-context>
             <connection-url>jdbc:mysql://localhost:3306/db1?autoReconnect=true</connection-url>
             <driver-class>org.gjt.mm.mysql.Driver</driver-class>
             <user-name>root</user-name>
             <password>root</password>
             </local-tx-datasource>
            </datasources>