Hibernate & JPA From Zero
Learn the ORM that sits under most Java backends: what an ORM really is, JPA vs Hibernate, entities and mapping, the EntityManager and persistence context, transactions and dirty checking, relationships, lazy-vs-eager fetching and the N+1 trap, JPQL and the Criteria API, inheritance, and caching. The magic Spring Data JPA hides, made plain.
- What an ORM Is & Why Hibernate Exists Your Java code thinks in objects; your database thinks in tables. An ORM bridges that gap so you work with objects and it writes the SQL. Here's the mental model, JPA vs Hibernate, and a minimal setup.
- Entities & Basic Mapping How a plain Java class becomes a database table: @Entity, @Id and key generation, @Column and @Table mapping, how Java types map to SQL, and letting Hibernate generate the schema.
- The EntityManager & Persistence Context The heart of Hibernate: the EntityManager is your handle to JPA, the persistence context is a per-transaction identity map and first-level cache, and every entity lives in one of four states.
- Transactions & the Unit of Work Why changing a field updates the row with no save call: transactions scope the persistence context, dirty checking diffs your managed objects, and flush sends the SQL — commit makes it stick.
- Mapping Relationships How JPA maps foreign keys to object references: @ManyToOne, @OneToMany with mappedBy, @ManyToMany join tables, owning vs inverse side, and the cascade and bidirectional-sync mistakes that cause most relationship bugs.
- Lazy vs Eager Fetching & the N+1 Problem How Hibernate decides when to load related data, why lazy loading throws LazyInitializationException, how the N+1 problem quietly turns one query into hundreds, and how JOIN FETCH, entity graphs, and batch fetching fix it.
- Querying: JPQL, Criteria & Native SQL How JPA gives you three layers of querying — JPQL for everyday object queries, the Criteria API for dynamic ones, and native SQL as the escape hatch — plus parameters, joins, and DTO projections.
- Inheritance & Embeddables How to map a Java class hierarchy onto tables (SINGLE_TABLE, JOINED, TABLE_PER_CLASS) and how embeddables fold a value object's fields into the owning table — plus when to reach for each.
- Caching & Performance How Hibernate's two caches work, how to batch writes instead of dribbling out one INSERT at a time, why reading the emitted SQL is the real skill, and when to step around the ORM entirely.
- Hibernate in the Real World & Where to Go Next How Hibernate actually shows up in production: as Spring Data JPA, behind versioned schema migrations, and beside raw SQL when the job calls for it. Plus what to build next.