Philipp Frauenthaler & Gregor Lucny
Hibernate: How to keep calm
#1about 6 minutes
Why you should use an ORM like Hibernate
Using an object-relational mapper (ORM) like Hibernate simplifies database access in Java by handling boilerplate code, type conversions, and transaction management that is complex with plain JDBC.
#2about 3 minutes
Mapping Java classes and the entity lifecycle
Entities move through transient, managed, and detached states, where changes to managed entities are automatically persisted to the database upon transaction commit.
#3about 2 minutes
Understanding Hibernate's caching layers
Hibernate uses a mandatory Level 1 cache scoped to the transaction to reduce database roundtrips, with an optional Level 2 cache for data shared across transactions.
#4about 3 minutes
Integrating Hibernate with Spring and Spring Data JPA
Spring Boot simplifies Hibernate configuration and transaction management, while Spring Data JPA further abstracts data access by generating repository implementations from interfaces.
#5about 3 minutes
Keeping your database schema in sync with Liquibase
Use a database migration tool like Liquibase and its diff plugin to automatically generate and apply schema changes based on your JPA entities, ensuring consistency.
#6about 3 minutes
Choosing an effective ID generation strategy
Client-generated UUIDs are often preferable to database auto-incrementing IDs because they are available before persistence and simplify data copying between environments.
#7about 3 minutes
Implementing equals and hashCode for JPA entities
Avoid using all properties in `equals` and `hashCode` for entities due to lazy loading and lifecycle issues; instead, base equality on the stable primary key.
#8about 5 minutes
Solving the N+1 query problem with join fetch
Prevent the N+1 query problem caused by lazy loading by using `JOIN FETCH` in your JPQL query to load related entities in a single database trip.
#9about 4 minutes
Processing large datasets with streaming and detaching
Handle large result sets efficiently by streaming data from the database and detaching processed entities from the session to prevent high memory consumption.
#10about 3 minutes
Managing transactions with external systems
Ensure data consistency with non-transactional systems like REST APIs by registering custom rollback actions using Spring's `TransactionSynchronizationManager`.
#11about 2 minutes
Automating actions with Hibernate entity listeners
Use Hibernate's entity listener hooks like `@PostPersist` and `@PostUpdate` to automatically trigger actions, such as sending messages to a message broker, when an entity changes.
#12about 16 minutes
Key takeaways for using Hibernate effectively
While Hibernate improves development efficiency, it is crucial to analyze the generated SQL, understand its internal workings, and recognize when it may not be the right tool for the job.
Related jobs
Jobs that call for the skills explored in this talk.
Matching moments
02:38 MIN
Overcoming the object-relational impedance mismatch
Databaseless Data Processing - High-Performance for Cloud-Native Apps and AI
31:26 MIN
Simplifying database persistence with Hibernate Panache
Quarkus. A Bliss for developers
20:07 MIN
Simplifying data access with the Jakarta Data specification
The Evolution of Enterprise Java with Jakarta EE 11 and Beyond
43:46 MIN
Q&A on virtual threads, reactive programming, and Java 21
Introduction and pitfalls of Java's new concurrency model
42:02 MIN
Q&A: Migrating projects and convincing your team
Why Kotlin is the better Java and how you can start using it
21:28 MIN
Adopting the Axon framework for true event sourcing
From event streaming to event sourcing 101
16:56 MIN
The object-relational impedance mismatch in persistence
Build ultra-fast In-Memory Database Apps and Microservices with Java
10:09 MIN
Choosing a familiar Java framework for microservices
Microservices: how to get started with Spring Boot and Kubernetes
Featured Partners
Related Videos
Our journey with Spring Boot in a microservice architecture
Michael Eder & Philipp Frauenthaler
Java 21: The Revolution of Virtual Threads - A Deep Dive
Christian Woerz
Bootiful Spring Boot 3
Josh Long
Slip Through the Boundaries of Legacy Systems with Kotlin and Spring WebFlux
Lukas Georgieff & Alberto Gisbert
Going reactive with Spring WebFlux
Michael Eder & Philipp Frauenthaler
Let's make your Java code Bug-Proof
Aicha Laafia
Write tests you love, not hate
Jens Happe
Are you done yet? Mastering long-running processes in modern architectures
Bernd Ruecker
Related Articles
View all articles.gif?w=240&auto=compress,format)



From learning to earning
Jobs that call for the skills explored in this talk.

Backend Entwickler - Java / Spring / Hibernate
Axontic GmbH
Bremen, Germany
Remote
Senior
Java
JIRA
Spring
Kotlin
+5
![Java Backend Engineer - (Spring Boot) [gn]](https://wearedevelopers.imgix.net/public/default-job-listing-cover.png?w=400&ar=3.55&fit=crop&crop=entropy&auto=compress,format)

Full-stack developer - Java/ Spring Boot/ Angular
ITech Consult AG
Bern, Switzerland
Remote
Intermediate
Java
Scrum
Splunk
Grafana
+5

Desarrollador Java Moderno con Spring Boot y Microservicios
SG Tech
Municipality of Madrid, Spain
Java
Kafka
DevOps
Docker
Microservices
+1

Fullstack Developer - Java EE/Spring/Angular/React
CodeCamp:N GmbH
Nürnberg, Germany
Intermediate
Azure
React
Spring
Angular
Project Management
+1

Senior Full-Stack Developer in Java (Spring Boot) and JavaScript (Vue)
ZeroHassle - Interactivated Solutions Group
Groningen, Netherlands
Remote
Senior
GIT
Java
REST
NoSQL
+5

Datenbank Architekt - MySQL / Java / Hibernate
WIBU-SYSTEMS AG
Karlsruhe, Germany
Java
Linux
MySQL
MariaDB
Hibernate
+1


Softwareentwickler - Spring Boot / Microservices / ERP
B & B Unternehmensberatung GmbH & Co. KG
Bad Dürkheim, Germany
Remote
Senior
Microservices