JPA Articles
Articles covering JPA relationship mapping, query methods, transactions, and performance optimization for data access design.
-
How to Implement Soft Delete in Spring Boot + JPA - Choosing Between @SQLDelete, @SQLRestriction, and Filter
A guide to transparently implementing soft delete (logical delete) in Spring Boot + Spring Data JPA. Covers when to use @SQLDelete + @SQLRestriction (formerly @Where) vs. @SoftDelete and @FilterDef, along with practical pitfalls like unique constraint conflicts, restoration handling, and recording the deleter.
-
How to Implement Optimistic Locking (@Version) with JPA in Spring Boot to Prevent Concurrent Update Conflicts
Learn how to prevent 'Lost Update' issues that occur in e-commerce inventory updates and reservation systems using the @Version annotation. Covers OptimisticLockException handling, retry strategies with Spring Retry, and writing concurrency tests with practical code examples.
-
How to Implement Type-Safe Dynamic Queries with QueryDSL in Spring Boot
A practical guide to integrating QueryDSL into Spring Boot, covering Q-type class generation via APT, dynamic query implementation with JPAQueryFactory, and pagination integration. Includes a comparison with Specification.
-
How to Automate Entity-DTO Mapping with MapStruct in Spring Boot
An implementation guide for auto-generating toDto()/toEntity() methods with MapStruct instead of writing them by hand. Covers adding dependencies, basic @Mapper usage, nested objects, custom conversions, and unit testing.
-
Implementing CRUD REST API with Spring Boot - Basic Structure of Controller, Service, and Repository
A step-by-step guide to implementing CRUD (Create, Read, Update, Delete) REST API with Spring Boot. Build the three-layer architecture of Controller, Service, and Repository from scratch, and walk through setting up all four endpoints: GET, POST, PUT, and DELETE.
-
How to Automatically Record Created and Updated Timestamps with JPA Auditing in Spring Boot
A guide to automatically recording entity creation and update timestamps using JPA Auditing in Spring Boot. Covers practical code for configuring @CreatedDate, @LastModifiedDate, @EnableJpaAuditing, and AuditorAware, including integration with Spring Security.
-
Which Should You Choose in Spring Boot: MyBatis or JPA? - Selection Criteria and Combined Usage Patterns
Are you unsure whether to choose MyBatis or JPA for your Spring Boot project? This article provides a thorough comparison of both from the perspectives of SQL control flexibility, learning cost, and maintainability, and presents practical selection criteria such as JPA for CRUD-focused use cases and MyBatis for complex reporting screens. Also covers how to implement a combined usage pattern.
-
Understanding Transaction Management with @Transactional in Spring Boot - How to Use Propagation Levels and Isolation Levels
A comprehensive guide to transaction management using the @Transactional annotation in Spring Boot, from basics to practical usage. Covers default behavior, all 7 propagation levels, 4 isolation levels, and common failure patterns where rollback does not work (checked exceptions, self-invocation) with real examples.
-
Spring Data JPA Query Methods: Naming Conventions and Examples
Master Spring Data JPA query method naming conventions — findBy, existsBy, countBy, and more. Covers multiple conditions, sorting, pagination, and @Query with practical examples.
-
Introduction to Spring Boot JPA Relationship Mapping - How to Use @OneToMany/@ManyToOne
A beginner-friendly guide to Spring Boot JPA's @OneToMany/@ManyToOne/@ManyToMany. Covers the differences between bidirectional and unidirectional mappings, mappedBy, cascade, FetchType, and the N+1 problem with code examples to resolve common pitfalls.