Using JNDI

Deploying to Tomcat

Deploying the Hibernate driver to Tomcat is very similar to deploying the JDBC driver - see Defining a JNDI Resource (Tomcat):

<!--
  // Note the use of 'com.nuodb.hib' in the url, all other properties
  // are the same as for the JDBC driver
  -->
<Resource name="jdbc/nuoDB"
    auth="Container"
    type="com.nuodb.jdbc.DataSource"
    ...
    url="jdbc:com.nuodb.hib://localhost/test" />

However there is one major consideration to be aware of.

  • The NuoDB Hibernate 5 driver (prior to V21.0.0-hib5) has a dependency on Hibernate in order to throw the appropriate Hibernate exceptions.

  • If you try to use the driver without Hibernate JARs on the CLASSPATH, you will get a ClassNotFoundException due to the missing StateStateException class.

This means that you must define the <Resource> in the META-INF/context.xml of your web-application. You cannot declare it in CATALINA_HOME/conf/server.xml (where CATALINA_HOME is the Tomcat installation directory), because the Hibernate JARs are not on Tomcat’s global classpath.

Deploying to TomEE

The configuration for TomEE is similar, except that two connection properties are different (replace driverClassName and url by jdbcDriver`and `jdbcUrl respectively).

The other DataSource properties, such as maxAge and validationQuery, are the same.

<!--
  // Note that these property names are NOT case-sensitive.
  -->
<Resource id="serviceDatabaseNuoDB" type="DataSource">
        jdbcDriver=com.nuodb.hibernate.NuoHibernateDriver
        jdbcUrl=jdbc:com.nuodb.hib://localhost/test
        userName=dba
        password=goalie
        connectionProperties=isolation=read_committed
        ...
</Resource>

Deploying to JBoss

To deploy the NuoDB Java Hibernate Dialect with JBoss:

  1. Copy nuodb-hibernate-<version>.jar to JBoss_Install_Dir/modules/org/hibernate/main.

  2. In the Hibernate module in JBoss_Install_Dir/modules/org/hibernate/main/module.xml, add the line

    <resource-root path="nuodb-hibernate-<version>.jar"/>
  3. Copy nuodb-jdbc-<version>.jar to JBoss_Install_Dir/modules/com/nuodb/jdbc/main.

  4. Edit JBoss_Install_Dir/modules/com/nuodb/jdbc/main/module.xml and add:

    <?xml version=1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.0" name="com.nuodb.jdbc">
        <resources>
            <resource-root path="nuodb-jdbc-<version>.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
        </dependencies>
    </module>