NuoDB and Hibernate
Join the DZone community and get the full member experience.
Join For FreeFor Java users, NuoDB provides a Hibernate dialect that supports both version 3.6.6 and 4.1.x of Hibernate.
A sample application that makes use of Hibernate and the NuoDB Hibernate dialect can be found in the samples directory of the NuoDB installation:
- %NUODB_HOME%\samples\hibernate (Windows)
- $NUODB_HOME/samples/hibernate (UNIX)
The sample application is built using Maven, so both the NuoDB dialect and JDBC jar files need to be installed into your Maven repository before attempting to build and run the sample.
The Hibernate dialect JDBC jar files are found in:
- %NUODB_HOME%\jar\nuodb-hibernate-1.0.jar (Windows)
- $NUODB_HOME/jar/nuodb-hibernate-1.0.jar (UNIX)
- %NUODB_HOME%\jar\nuodbjdbc.jar (Windows)
- $NUODB_HOME/jar/nuodbjdbc.jar (UNIX)
To install the jar files into your local repository (for Windows, just change the path):
/opt/nuodb/samples/hibernate $ mvn install:install-file -DgroupId=com.nuodb -DartifactId=nuodb-jdbc -Dversion=1.0 -Dpackaging=jar -Dfile=/opt/nuodb/jar/nuodbjdbc.jar [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Hibernate Sample 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ nuodb-hibernate-sample --- [INFO] Installing /opt/nuodb/jar/nuodbjdbc.jar to /Users/johnblais/.m2/repository/com/nuodb/nuodb-jdbc/1.0/nuodb-jdbc-1.0.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.587s [INFO] Finished at: Thu Apr 11 11:58:59 EDT 2013 [INFO] Final Memory: 3M/81M [INFO] ------------------------------------------------------------------------
/opt/nuodb/samples/hibernate $ mvn install:install-file -DgroupId=com.nuodb -DartifactId=nuodb-hibernate -Dversion=1.0 -Dpackaging=jar -Dfile=/opt/nuodb/jar/nuodb-hibernate-1.0.jar [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Hibernate Sample 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) @ nuodb-hibernate-sample --- [INFO] Installing /opt/nuodb/jar/nuodb-hibernate-1.0.jar to /Users/johnblais/.m2/repository/com/nuodb/nuodb-hibernate/1.0/nuodb-hibernate-1.0.jar [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.501s [INFO] Finished at: Thu Apr 11 11:59:29 EDT 2013 [INFO] Final Memory: 3M/81M [INFO] ------------------------------------------------------------------------
To build the application:
/opt/nuodb/samples/hibernate $ mvn compile [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Hibernate Sample 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) @ nuodb-hibernate-sample --- [WARNING] File encoding has not been set, using platform encoding MacRoman, i.e. build is platform dependent! [WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 2 resources [INFO] Copying 2 resources [INFO] [INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) @ nuodb-hibernate-sample --- [INFO] Compiling 4 source files to /opt/nuodb/samples/hibernate/target/classes [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.302s [INFO] Finished at: Thu Apr 11 11:59:41 EDT 2013 [INFO] Final Memory: 9M/81M [INFO] ------------------------------------------------------------------------
To execute the application:
/opt/nuodb/samples/hibernate $ mvn exec:java [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Hibernate Sample 1.0-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] >>> exec-maven-plugin:1.1:java (default-cli) @ nuodb-hibernate-sample >>> [INFO] [INFO] <<< exec-maven-plugin:1.1:java (default-cli) @ nuodb-hibernate-sample <<< [INFO] [INFO] --- exec-maven-plugin:1.1:java (default-cli) @ nuodb-hibernate-sample --- Found 2 user records: User (1/0), Username: fred, Name: Fred Flintstone, admin home: Street: '301 Cobblestone Way', Zipcode: '00001', City: 'Bedrock' bill: Street: '301 Cobblestone Way', Zipcode: '00001', City: 'Bedrock' ship: Street: '1 Slate Drive', Zipcode: '00002', City: 'Granitetown' User (2/0), Username: barney, Name: Barney Rubble, member home: Street: '303 Cobblestone Way', Zipcode: '00001', City: 'Bedrock' bill: Street: '303 Cobblestone Way', Zipcode: '00001', City: 'Bedrock' ship: Street: '1 Slate Drive', Zipcode: '00002', City: 'Granitetown' Found 2 user records: Found 2 user records: User (1/1), Username: fred, Name: FRED FLINTSTONE, member home: Street: '301 Cobblestone Way', Zipcode: '00001', City: 'Bedrock' bill: Street: '301 COBBLESTONE WAY', Zipcode: '00001', City: 'BEDROCK' ship: Street: '1 Slate Drive', Zipcode: '00002', City: 'Granitetown' User (2/1), Username: barney, Name: BARNEY RUBBLE, member home: Street: '303 Cobblestone Way', Zipcode: '00001', City: 'Bedrock' bill: Street: '303 COBBLESTONE WAY', Zipcode: '00001', City: 'BEDROCK' ship: Street: '1 Slate Drive', Zipcode: '00002', City: 'Granitetown' [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.692s [INFO] Finished at: Thu Apr 11 11:59:53 EDT 2013 [INFO] Final Memory: 3M/81M [INFO] ------------------------------------------------------------------------ /opt/nuodb/samples/hibernate $
To validate the results, we can use nuosql to examine the data:
/opt/nuodb/samples/hibernate $ /opt/nuodb/bin/nuosql --user cloud --password user test@localhost SQL> show schemas Schemas containing tables SAMPLE SYSTEM SQL> use SAMPLE; SQL> show tables; Tables in schema SAMPLE ADDRESS BILLING_ADDRESS USERS SQL> select * from users; USER_ID OBJ_VERSION FIRSTNAME LASTNAME USERNAME PASSWORD EMAIL RANK IS_ADMIN CREATED HOME_STREET HOME_ZIPCODE HOME_CITY -------- ------------ ---------- ---------- --------- --------- ------------------ ----- --------- ----------------------- ------------------- ------------- ---------- 1 1 FRED FLINTSTONE fred fredf@example.com 0 0 2013-04-11 11:59:53.548 301 Cobblestone Way 00001 Bedrock 2 1 BARNEY RUBBLE barney barney@example.com 0 0 2013-04-11 11:59:53.583 303 Cobblestone Way 00001 Bedrock SQL>
Notes
For those of you that are familiar with Hibernate, the application uses Hibernate configuration files. It could have been built just as easily using Java annotations. For more on Hibernate, see http://www.hibernate.org/docs, start with the “Getting Started Guide” for your version.
To learn more about maven, see http://maven.apache.org/guides/
Unsupported Hibernate features
NuoDB does not currently support scrollable result sets.
Published at DZone with permission of Seth Proctor, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.
Trending
-
Alpha Testing Tutorial: A Comprehensive Guide With Best Practices
-
Web Development Checklist
-
What Is React? A Complete Guide
-
Essential Architecture Framework: In the World of Overengineering, Being Essential Is the Answer
Comments