🍃 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

    Spring Data JPA eliminates boilerplate data access code by generating repository implementations at startup from interface definitions.

  4. 4.Entity Mapping

    JPA entity mapping defines how Java classes and their fields translate to database tables and columns.

  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 maps a relationship where one entity instance is associated with exactly one instance of another entity.

  9. 9.OneToMany

    @OneToMany maps a relationship where one entity instance is associated with a collection of another entity's instances — one Order has many OrderItems, one Department…

  10. 10.ManyToOne

    @ManyToOne is the owning side of the most common JPA relationship — many child rows reference one parent row via a foreign key column.

  11. 11.ManyToMany

    @ManyToMany maps a relationship where each instance of entity A can be associated with multiple instances of entity B, and vice versa.

  12. 12.Cascade Types

    Cascade types control which JPA lifecycle operations — persist, merge, remove, refresh, detach — are automatically propagated from a parent entity to its associated…

  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

    Native queries execute raw SQL directly against the database, bypassing JPQL translation.

  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 through @EnableTransactionManagement and a PlatformTransactionManager.

  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, preventing other transactions from modifying it until the lock is released.

  23. 23.Entity Lifecycle

    JPA entities move through four states — transient, managed, detached, and removed — as they interact with the EntityManager and the persistence context.

  24. 24.Criteria API

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