Spring boot data access
Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/spring-boot-data-access
Best practices for JPA, Hibernate, and Database interactions in Spring Boot. Use when implementing JPA entities, repositories, or database access in Spring Boot. (triggers: **/*Repository.java, **/*Entity.java, jpa-repository, entity-graph, transactional, n-plus-1)From its SKILL.md
npx -y skills add ComeOnOliver/skillshub --skill spring-boot-data-accessAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
2.0 KB, 434 tokens by cl100k_base, as published. Nobody here has run it
Spring Boot Data Access
Priority: P0
Implementation Guidelines
JPA & Hibernate (Spring Data JPA)
- Read-Only: Default to
@Transactional(readOnly = true)on Services to optimize DB resources. - Projections: Use
Java Recordsfor Read-Only query results. Avoid fetching full@Entityobjects when not necessary. - Pagination: ALWAYS use
PageableandSlice(orPage) to prevent loading massive datasets. - Spring Data: Prefer
JpaRepositoryandQuery methods. Use@Querywith JPQL for complex logic. Use Flyway or Liquibase for migrations; never usespring.jpa.hibernate.ddl-auto=create(ddl-auto) in production.
Query & Transaction Optimization
- N+1 Problem: Fix
N+1selects usingJOIN FETCH(JPQL) or@EntityGraph. - Open-In-View: Set
spring.jpa.open-in-view=falseinapplication.yaml. - Bulk Operations: Use
@Modifyingwith@Queryfor updates/deletes to bypass EntityManager overhead. - Connection Pool: Configure
HikariCPwith explicitmaximum-pool-size. Tune Hikari pool-size based on expected concurrent queries.
Anti-Patterns
- No N+1 Selects: Use
JOIN FETCHor@EntityGraphinstead of lazy-loading in loops. - Entity Inflation: Don't use
@Data(Lombok) on Entities as it breaks Proxy andhashCode/equalsperformance. - Transactional Leak: Don't put
@Transactionalon publicRepositorymethods if theServiceis already transactional. - Raw SQL: Avoid native SQL unless JPQL/Criteria API is insufficient.
References
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.