Skip to main content
Let’s create a simple Hibernate application that connects to Regatta using the Regatta JDBC driver and Hibernate dialect.

Connection Details

Regatta connection parameters are configured in hibernate.cfg.xml:

Example Appliaction

This example application will:
  1. Create an employees table.
  2. Insert four employees using Hibernate ORM.
  3. Query and print the results.
  4. Delete the rows and drop the table.

Project Structure

Create a new Maven project folder, for example regatta-hibernate-example/, with the following layout:
Start your Java sources with the Regatta example package:
Note that you should import all relevant classes based on the functionality of your application and its requirements.

Employee Entity

Create the Employee entity and save it as: src/main/java/dev/regatta/hibernate_example/Employee.java

Hibernate Main Program

Create the main program and save it as: src/main/java/dev/regatta/hibernate_example/HibernateExample.java

Hiberante Configuration

Save the Hibernate configuration as:src/main/resources/hibernate.cfg.xml
The property hbm2ddl.auto controls whether Hibernate automatically manages your database schema. When set to none, Hibernate will not attempt to create, update, validate, or drop tables. If you prefer Hibernate to manage the schema for you during development, you may change this property:
  • create — Drops the existing schema (if any) and creates all tables on startup.
  • create-drop — Creates the schema on startup and drops it on shutdown.
  • update — Tries to update the schema to match your entities without dropping tables.
  • validate — Validates that the schema matches your entities without modifying anything.

Maven Project Setup

Create a pom.xml in the project root:

Running the Application

Compile and run the application:
Expected output: