What Hibernate is
In the JDBC chapter of the Java tutorial you wrote SQL by hand, filled a PreparedStatement and copied every column of a ResultSet into an object. ORM (object-relational mapping) does that routine work for you: you describe once how a class maps to a table, and from then on you save and load ordinary Java objects. The library writes the SQL itself.
JPA and Hibernate
Two names always come together:
| Name | What it is |
|---|---|
| Jakarta Persistence (JPA) | A standard: a set of annotations and interfaces in the jakarta.persistence package. It contains no working code |
| Hibernate ORM | The most popular implementation of that standard, plus its own extras in the org.hibernate package |
You write code against the standard — @Entity, EntityManager, JPQL queries — and Hibernate does the work underneath. Where the standard is not enough (natural ids, batch loading, statistics), you use Hibernate classes directly.
Versions
The course uses Hibernate ORM 7.4 (7.4.12.Final), which implements Jakarta Persistence 3.2. Hibernate 7 needs Java 17 or newer; the examples run on Java 25. Hibernate 8 is still in beta at the time of writing.
JDBC and Hibernate side by side
Saving a post through JDBC:
// src/main/java/com/example/blog/JdbcExample.java
try (PreparedStatement st = conn.prepareStatement("insert into post (id, title) values (?, ?)")) {
st.setLong(1, 1);
st.setString(2, "Hello, Hibernate");
st.executeUpdate();
}The same with Hibernate:
// src/main/java/com/example/blog/Main.java
emf.runInTransaction(em -> em.persist(new Post("Hello, Hibernate")));There is no SQL in the second example: Hibernate knows from the Post class which table and columns to use, picks the id itself and sends insert into Post (title,id) values (?,?) to the database. How to set this up is the topic of the next lessons.
Where you meet Hibernate
- Spring Boot: the
spring-boot-starter-data-jpastarter brings in Hibernate. The entities are exactly the same as in this course, but instead of anEntityManageryou usually work through Spring Data repositories — interfaces likePostRepository extends JpaRepository<Post, Long>. - Quarkus and Jakarta EE servers also use Hibernate as the JPA implementation.
This course uses plain Java SE with Maven and the in-memory H2 database, so that nothing hides how Hibernate works. Everything you learn applies inside a framework too.
The running example
Throughout the course we build the data model of a blog: posts (Post), comments (Comment), authors (Author) and tags (Tag). Each lesson adds one idea to it.
Common mistake
Old articles and Hibernate 5 examples import annotations from javax.persistence. Since Jakarta EE 9 the package is called jakarta.persistence, and with Hibernate 7 the old import does not compile:
Post.java:4: error: package javax.persistence does not exist
import javax.persistence.Entity;
^When you copy code from the internet, replace javax.persistence with jakarta.persistence.