Configuration
Set up Hibernate 6 without mortgaging production.
Configuration and Setup
Hibernate configuration is where, in five lines of properties, you make decisions whose consequences you will pay for years. Two of them deserve a closer look: how the database schema is created, and how SQL queries are made visible.
The first decision is the schema. Hibernate can derive a CREATE TABLE from your entities, and that is extremely convenient during the first three days of a project. Most teams leave this setting in place, push it to production, and discover one morning that a column renamed in the code caused an empty column to appear in the database next to the old one, which is full of data. There is no going back: Hibernate does not know how to migrate data, only how to reconcile structures.
The second decision is visibility. An ORM produces SQL that you did not write; as long as that SQL is not in front of you, you can neither understand nor fix a performance problem. The running theme of this course, the N+1 queries, is literally invisible without logging enabled. That is why this lesson configures logging before everything else.
We cover both ways to bootstrap: the Jakarta EE persistence.xml, which remains the reference for understanding what is going on, and the Spring Boot configuration, which is what you will write in practice.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion