Connecting to a Database Using Java Hibernate Driver

Making a Database Connection

The connection URL when using the Hibernate driver has a different driver identifier, com.nuodb.hib, but is otherwise the same as the JDBC driver. For example: jdbc:com.nuodb.hib://localhost/test. See NuoDB Connection URL.

The driver class name is: com.nuodb.hibernate.NuoHibernateDriver.

JPA with Hibernate

JPA configuration is performed by the META-INF/persistence.xml file which must be on the class path. Below are the relevant properties to set. Note that this file supports both JPA specific properties (prefix javax.persistence) and also Hibernate specific properties.

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

<!-- The configuration file for JPA -->
	version="2.0" xmlns="">

	<!-- Each persistence unit correspond to a database -->
	<persistence-unit name="Hockey"	transaction-type="RESOURCE_LOCAL">
			<!-- JPA Properties -->
			<property name="javax.persistence.jdbc.driver"
                      value="com.nuodb.hibernate.NuoHibernateDriver" />
			<property name="javax.persistence.jdbc.url"
                      value="jdbc:com.nuodb.hib://localhost/test" />
			<property name="javax.persistence.jdbc.user" value="dba" />
			<property name="javax.persistence.jdbc.password" value="goalie" />

			<!-- HIBERNATE Properties -->
			<property name="hibernate.connection.schema" value="Hockey" />
			<property name="hibernate.dialect"
                      value="com.nuodb.hibernate.NuoDBDialect" />


To access the database requires an EntityManagerFactory. Its constructor takes the name of the persistence unit whose configuration it should use:

EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("Hockey");

All data access occurs via the EntityManager which also supports transaction management. Every EntityManager creates a connection for itself (although you do not typically access the connection directly):

EntityManager em = entityManagerFactory.createEntityManager();

NuoDB with JPA, Hibernate, Spring and Spring Boot

For an example of using JPA and Hibernate with Spring and Spring Boot, refer to the examples.

Hibernate Session API

In pure Hibernate (without JPA), database connections are configured using a configuration file. Below are the relevant properties to set in hibernate.cfg.xml:

<!DOCTYPE hibernate-configuration SYSTEM "">
        <property name="hibernate.dialect">com.nuodb.hibernate.NuoDBDialect</property>
        <property name="hibernate.connection.driver_class">com.nuodb.hibernate.NuoHibernateDriver</property>
        <property name="hibernate.connection.url">jdbc:com.nuodb.hib://localhost/test</property>
		<property name="hibernate.connection.username">dba</property>
		<property name="hibernate.connection.password">goalie</property>
        <property name="hibernate.connection.schema">sample</property>
The hibernate. prefix to these property names is optional. Thus hibernate.connection.url and connection.url are equivalent.

To configure Hibernate in your application:

Configuration configuration = new Configuration();


NuoDB Specific Properties

These are the property settings specific to NuoDB:

Property Description Example


Fully qualified class name for the NuoDB Hibernate Dialect.



Fully qualified class name for the Hibernate Driver class.



Very similar to the NuoDB JDBC Connection String, except the subprotocol name (driver identifier) is com.nuodb.hib instead of com.nuodb.


Accessing the Database

A JDBC connection corresponds to a Hibernate Session.

SessionFactory factory = configuration.buildSessionFactory();

try ( Session session = factory.openSession() ) {
    ... begin transaction (optional)
    ... do work with entities
    ... commit or rollback as necessary