🍃 Spring Boot

Spring Boot Data JPA & Hibernate

24 lessons in this section of the Spring Boot tutorial. Work through them in order, or jump to the one you need.

  1. 1.Introduction to JPA

    The Java Persistence API (JPA) is a specification for mapping Java objects to relational database tables — a technique known as Object-Relational Mapping (ORM).

  2. 2.Hibernate Basics

    Hibernate is the most widely used Java ORM (Object-Relational Mapping) framework and the default JPA provider in Spring Boot.

  3. 3.Spring Data JPA

    Learn Spring Data JPA: repositories, derived queries, @Query, pagination, projections, specifications and auditing, with pitfalls and the SQL each one generates.

  4. 4.Entity Mapping

    Learn JPA entity mapping in Spring Boot 3: @Entity and @Table, column mapping, primary key strategies, enums, @Embedded, @ElementCollection and inheritance, with a…

  5. 5.Table Mapping

    Table mapping controls how JPA entities translate to database tables — table names, schemas, indexes, unique constraints, and join tables for relationships.

  6. 6.Primary Keys

    Primary keys uniquely identify every row in a table.

  7. 7.Composite Keys

    A composite key is a primary key made up of two or more columns.

  8. 8.OneToOne

    @OneToOne links one entity row to exactly one row of another entity, with the foreign key on the owning side.

  9. 9.OneToMany

    @OneToMany maps a parent that owns a collection of children: one Order has many OrderItems, one Department has many Employees.

  10. 10.ManyToOne

    @ManyToOne maps the relationship where many child rows point at one parent row through a foreign key column: many comments belong to one post, many orders to one…

  11. 11.ManyToMany

    How to map many-to-many relationships with Spring Data JPA and Hibernate 6: the plain @ManyToMany with a join table, the explicit join entity for tables that carry extra…

  12. 12.Cascade Types

    Understand JPA cascade types in Spring Boot: what PERSIST, MERGE, REMOVE, REFRESH, DETACH and ALL do, how orphanRemoval differs, which cascade to use for owned and…

  13. 13.Fetch Types

    Fetch types control when Hibernate loads associated entities — immediately with the parent (EAGER) or only when the association is first accessed (LAZY).

  14. 14.JPQL

    JPQL (Jakarta Persistence Query Language) is the object-oriented query language defined by the JPA specification.

  15. 15.Native Queries

    Use native SQL queries in Spring Data JPA the safe way: @Query(nativeQuery = true), countQuery pagination, interface and DTO projections, @Modifying with…

  16. 16.Query Methods

    Query methods are Spring Data JPA's mechanism for generating queries automatically from repository method names.

  17. 17.Custom Queries

    Custom queries in Spring Data JPA cover every scenario where derived query methods and simple @Query annotations are insufficient — dynamic multi-condition searches…

  18. 18.Pagination & Sorting

    Spring Data JPA provides first-class pagination and sorting through the Pageable abstraction, Page<T>, Slice<T>, and Sort.

  19. 19.Transactions

    Spring Boot auto-configures transaction management, so you can use @Transactional without adding @EnableTransactionManagement.

  20. 20.Auditing

    Spring Data JPA auditing automatically populates created and modified timestamps and user fields on entities.

  21. 21.Optimistic Locking

    Optimistic locking prevents lost updates in concurrent environments without holding database locks.

  22. 22.Pessimistic Locking

    Pessimistic locking acquires a database lock when a row is read, so other transactions cannot modify it until the lock is released.

  23. 23.Entity Lifecycle

    JPA entity lifecycle explained: transient, managed, detached and removed states, persist vs merge, flush, @PrePersist/@PostLoad callbacks, cascade and common pitfalls.

  24. 24.Criteria API

    The JPA Criteria API builds type-safe, dynamic queries programmatically using a fluent builder rather than string-based JPQL.