Connection Details
Regatta connection parameters are configured inhibernate.cfg.xml:
Example Appliaction
This example application will:- Create an
employeestable. - Insert four employees using Hibernate ORM.
- Query and print the results.
- Delete the rows and drop the table.
Project Structure
Create a new Maven project folder, for exampleregatta-hibernate-example/, with the following layout:
Employee Entity
Create theEmployee 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 apom.xml in the project root:
This
pom.xml assumes you already installed the Regatta JDBC driver and Hibernate dialect locally.