When to use this skill
Use this skill whenever the user wants to:
- Define entities, repositories, query methods, and transactions with Spring Data JPA
- Configure data sources, JPQL, specifications, and auditing
How to use this skill
- Core: @Entity, JpaRepository, CrudRepository; method name queries, @Query, Pageable.
- Advanced: @EntityGraph, Specification, auditing @CreatedDate; multiple data sources and transaction propagation.
- Reference:https://spring.io/projects/spring-data-jpa
Best Practices
- N+1 and fetch strategies; pagination and batch operations.
- Separate entities from DTOs; define clear transaction boundaries.
Keywords
spring data jpa, JPA, Repository, persistence
Common Pitfalls (Gotchas)
- Version compatibility: Pay attention to compatibility between framework versions and dependency libraries; APIs may differ across versions.
- Configuration file format: Configuration file format errors are the most common issue; it is recommended to use the editor's syntax checking.
- Environment variables: Ensure all necessary environment variables are set correctly, and do not hardcode sensitive information.
- Dependency conflicts: When multiple versions coexist, watch out for dependency conflicts and use a lock file to pin versions.
- Performance pitfalls: In large data volume scenarios, pay attention to performance optimization and avoid common issues such as N+1 queries.
Usage Flow
Step 1: Environment preparation
Ensure the development environment has the necessary dependencies and tools installed.
Step 2: Configuration initialization
Perform basic configuration according to project requirements.
Step 3: Using core features
Implement the core features according to the example code.
Step 4: Testing and verification
Run tests to ensure the functionality works properly.
Step 5: Deployment and release
After completing development, proceed with deployment and monitoring.