DevNotes
Support
Spring · 17 chapters

Spring Data JPA & Hibernate

Repositories and save() internals, derived query keywords, pagination and keyset scrolling, @Query and JPQL, native SQL, entity mapping and ID strategies, the persistence context and dirty checking, relationships and cascading, fetching and the N+1 problem, transactions, propagation and locking, projections, Specifications and auditing, inheritance and composite keys, second-level caching, HikariCP, Flyway migrations, testing with Testcontainers and advanced Hibernate features.

CHAPTER 01

Introduction to Spring Data JPA

From JDBC and Hibernate to Spring Data JPA, the layers involved, setup and configuration, a first entity and repository, CRUD methods, how save() decides between persist and merge, and the repository interface hierarchy.

6 min · 7 Q&A · 9 examples
CHAPTER 02

Repository Methods (Derived Queries)

How Spring Data parses method names into queries, prefixes like findBy, existsBy, countBy and deleteBy, Top and First, Distinct, IgnoreCase, And and Or, supported return types, and the pitfalls of derived queries.

6 min · 6 Q&A · 18 examples
CHAPTER 03

Derived Query Keywords

Every common keyword Spring Data JPA understands in method names — comparison, Between, Before/After, Like, Containing, StartingWith, In, True/False, Null, IgnoreCase and OrderBy — combining them, nested properties and associations, and when to stop.

5 min · 5 Q&A · 10 examples
CHAPTER 04

Pagination & Sorting

Why never to load everything, Pageable and PageRequest, Page metadata, the SQL behind a page, Sort and multi-column sorting, pageable REST endpoints, Page vs Slice, deep-page performance and keyset pagination with Spring Data's scrolling API.

7 min · 5 Q&A · 14 examples
CHAPTER 05

@Query & JPQL

Why @Query exists, JPQL vs SQL, named and positional parameters, LIKE, aggregates, GROUP BY and HAVING, @Modifying updates and deletes and their persistence-context pitfalls, joins, JOIN FETCH, subqueries, DTO projections and common mistakes.

11 min · 6 Q&A · 25 examples
CHAPTER 06

Native SQL Queries

What native queries are, JPQL vs native SQL and when to choose each, parameters, mapping results to entities, Object[] and interface projections, native updates, deletes and inserts, pagination with countQuery, sorting, stored procedures, vendor functions, CTEs, window functions and performance.

10 min · 5 Q&A · 20 examples
CHAPTER 07

Entity Mapping Essentials

What makes a class an entity, @Table and @Column, primary keys and generation strategies (IDENTITY, SEQUENCE, UUID), enums with EnumType.STRING, dates, BigDecimal for money, @Transient, @Lob, embeddables, naming strategies and schema validation.

7 min · 6 Q&A · 9 examples
CHAPTER 08

Persistence Context & Entity Lifecycle

The persistence context as a first-level cache and unit of work, the four entity states, persist, merge, remove and detach, dirty checking, flush modes and timing, getReferenceById, LazyInitializationException, Open Session in View and lifecycle callbacks.

7 min · 8 Q&A · 7 examples
CHAPTER 09

Relationships & Cascading

@ManyToOne, @OneToMany, @OneToOne and @ManyToMany, the owning side and mappedBy, join columns and join tables, bidirectional helper methods, cascade types, orphanRemoval, default fetch types, equals/hashCode for entities and JSON recursion.

7 min · 7 Q&A · 9 examples
CHAPTER 10

Fetching Strategies & the N+1 Problem

LAZY vs EAGER, how proxies and lazy collections work, the N+1 select problem and how to detect it, JOIN FETCH, @EntityGraph, @BatchSize and default batch fetch size, DTO projections, collection fetching with pagination, MultipleBagFetchException and JDBC batching.

6 min · 7 Q&A · 11 examples
CHAPTER 11

Transactions & Locking

How @Transactional works through proxies, where to put it, readOnly, rollback rules for checked exceptions, propagation (REQUIRED, REQUIRES_NEW, NESTED…), isolation levels, the self-invocation trap, optimistic locking with @Version and pessimistic locks with @Lock.

8 min · 7 Q&A · 12 examples
CHAPTER 12

Projections, Specifications & Auditing

Interface, class/record and dynamic projections, closed vs open projections, dynamic search with Specifications and JpaSpecificationExecutor, Query by Example, custom repository fragments, and auditing with @CreatedDate, @LastModifiedBy and AuditorAware.

7 min · 6 Q&A · 12 examples
CHAPTER 13

Inheritance, Composite Keys & Collections

Mapping class hierarchies with @MappedSuperclass, SINGLE_TABLE, JOINED and TABLE_PER_CLASS, polymorphic queries, composite primary keys with @EmbeddedId and @IdClass, join entities with @MapsId, @ElementCollection and @NaturalId.

9 min · 6 Q&A · 13 examples
CHAPTER 14

Caching, Connection Pooling & Migrations

Hibernate's second-level cache and query cache, cache concurrency strategies and when not to cache, sizing and tuning the HikariCP connection pool, leak detection, and versioned schema migrations with Flyway and Liquibase.

8 min · 6 Q&A · 3 examples
CHAPTER 15

Testing the Data Layer

What to test in a JPA application, @DataJpaTest and TestEntityManager, why H2 can mislead you, Testcontainers with @ServiceConnection, flushing to catch constraint errors, the false confidence of transactional tests, asserting query counts to catch N+1, and test data strategies.

6 min · 5 Q&A · 6 examples
CHAPTER 16

Advanced Hibernate Features

Soft deletes with @SoftDelete and @SQLRestriction, JSON columns, @Formula and @DynamicUpdate, change history with Hibernate Envers, domain events, StatelessSession for bulk jobs, multiple data sources, read-replica routing, multi-tenancy, Querydsl, and when R2DBC or plain JDBC is the better tool.

8 min · 6 Q&A · 14 examples
CHAPTER 17

JPA & Hibernate Interview Cheat Sheet

The whole topic on one page — repositories, queries, mapping, the persistence context, relationships, fetching and N+1, transactions and locking, inheritance, caching, pooling, migrations and testing — plus the most-asked interview questions, scenario questions and classic traps.

8 min · 24 Q&A · 0 examples