JPA Articles
Articles covering JPA relationship mapping, query methods, transactions, and performance optimization for data access design.
-
How to Reduce Boilerplate Code with Lombok in Spring Boot
A practical explanation of the roles and proper usage of Lombok annotations frequently used in Spring Boot development (@Data, @Builder, @RequiredArgsConstructor, @Slf4j, etc.). Also covers pitfalls when used with JPA Entity and how to combine it with constructor injection.
-
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 REST API CRUD with Spring Boot - Basic Structure of Controller, Service, and Repository
A step-by-step guide to implementing REST API CRUD (Create, Read, Update, Delete) with Spring Boot using a three-layer structure of Controller, Service, and Repository. Get the four GET/POST/PUT/DELETE endpoints running via copy-paste, with end-to-end coverage including verification using curl.
-
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.
-
MyBatis vs JPA in Spring Boot - Selection Criteria and Combined Usage Patterns [With Comparison Table]
Wondering whether to choose MyBatis or JPA for your Spring Boot project? This article organizes SQL control flexibility, learning cost, performance, and maintainability in a comparison table, and explains practical decision flowcharts, the difference between #{} and ${}, and concrete configuration examples for using both together. Get all the decision criteria in one place.
-
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.
-
Have You Ever Been Unsure How to Write Spring Data JPA Query Methods?
A reference table summarizing the naming conventions of Spring Data JPA query methods (findBy/existsBy/countBy/deleteBy). Check keywords like Containing/StartingWith/GreaterThan/Between/In/IsNull along with their generated SQL and usage examples in a quick-reference table. Also explains custom queries with @Query, sorting, and paging with practical examples.
-
Introduction to Spring Boot JPA Relationship Mapping - How to Use @OneToMany/@ManyToOne/@ManyToMany and mappedBy
A beginner-friendly explanation of @OneToMany/@ManyToOne/@ManyToMany/mappedBy in Spring Boot JPA. Resolves common pitfalls with code examples covering the differences between bidirectional/unidirectional relationships, cascade, FetchType, the N+1 problem, and circular reference countermeasures.