jpa

Spring Data JPA repository patterns

Spring Data JPA eliminates boilerplate DAO code with repository interfaces. I extend JpaRepository to get CRUD methods automatically—save, findById, findAll, delete. Custom query methods use method naming conventions—findByEmailAndActiveTrue generates

Database transactions and isolation levels

Spring's @Transactional manages database transactions declaratively. Transaction propagation controls behavior when methods call other transactional methods—REQUIRED, REQUIRESNEW, NESTED. Isolation levels prevent concurrent access issues—READUNCOMMITT

Pagination and sorting with Spring Data

Spring Data provides elegant pagination and sorting mechanisms. Pageable interface defines page number, size, and sort parameters. Page wraps results with metadata—total elements, total pages, current page. Sort defines ordering by multiple properties

Multi-tenancy for SaaS applications

Multi-tenancy serves multiple customers (tenants) from single application instance. Schema-per-tenant isolates data in separate databases. Shared schema with tenant ID column partitions data within tables. Discriminator-based approach uses JPA filters