Menu

Setting Up a Hibernate Project

Setting Up a Hibernate Project

Requirements

Hibernate 7 needs Java 17 or higher. You also need a build tool such as Maven or Gradle, and a relational database with its JDBC driver.

Adding Dependencies

The core library is hibernate-core. Note that its group ID is org.hibernate.orm, not the older org.hibernate used in Hibernate 5.

<dependency>
    <groupId>org.hibernate.orm</groupId>
    <artifactId>hibernate-core</artifactId>
    <version>7.4.11.Final</version>
</dependency>

Code Explanation:

  • org.hibernate.orm is the group ID used from Hibernate 6 onward.
  • hibernate-core contains the ORM engine and brings the Jakarta Persistence API with it.
  • The version shown is the latest 7.4 release at the time of writing. Use the latest 7.4.x release when you build your own project.

Adding a JDBC Driver

Hibernate does not include a database driver. Add your database driver as a separate dependency.

  • H2: com.h2database:h2, useful for learning because it needs no installation.
  • MySQL: com.mysql:mysql-connector-j
  • PostgreSQL: org.postgresql:postgresql

Project Layout

A standard Maven layout works without changes. Java classes go in src/main/java, and configuration files such as hibernate.cfg.xml go in src/main/resources so they appear on the classpath.


Hibernate Tutorial

AP

Abhishek Pati



Learn via Video Course

Java Programming ( Telugu) Logo

Java Programming ( Telugu)

11 hrs



Get in Touch For Details