Skip to content
Back to skills

Spring Boot Data Access

ASecurity

Optimize JPA, Hibernate, and database interactions in Spring Boot. Use when implementing JPA entities, repositories, or database access in Spring Boot.

  • 549 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added June 6, 2026
developmentjavasqlspringapidatabaseperformance

Works with

  • api

Security analysis

A100/100

Pro scans all 3 files and shows the line behind each finding

Scanned June 6, 2026

npx -y skills add HoangNguyen0403/agent-skills-standard --skill spring-boot-data-access --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Spring Boot Data Access?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Spring Boot Data Access
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/hoangnguyen0403-spring-boot-data-access/badge)](https://www.skillsdirectory.com/skills/hoangnguyen0403-spring-boot-data-access)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: spring-boot-data-access
description: Optimize JPA, Hibernate, and database interactions in Spring Boot. Use when implementing JPA entities, repositories, or database access in Spring Boot.
metadata:
  triggers:
    files:
    - '**/*Repository.java'
    - '**/*Entity.java'
    keywords:
    - jpa-repository
    - entity-graph
    - transactional
    - n-plus-1
---
# Spring Boot Data Access

## **Priority: P0**

## Configure JPA and Spring Data

- **Read-Only**: Default to **`@Transactional(readOnly = true)`** on Services to optimize DB resources.
- **Projections**: Use **`Java Records`** for **Read-Only** query results. Avoid fetching full **`@Entity`** objects when not necessary.
- **Pagination**: ALWAYS use **`Pageable`** and **`Slice`** (or `Page`) to prevent loading massive datasets.
- **Spring Data**: Prefer **`JpaRepository`** and **`Query methods`**. Use **`@Query`** with JPQL for complex logic. Use Flyway or Liquibase for migrations; never use `ddl-auto=create` in production.

See [implementation examples](references/implementation.md) for repository projections, EntityGraph, and transactional patterns.

## Optimize Queries and Transactions

- **N+1 Problem**: Fix **`N+1`** selects using **`JOIN FETCH`** (JPQL) or **`@EntityGraph`**.
- **Open-In-View**: Set `spring.jpa.open-in-view=false` in **`application.yaml`**.
- **Bulk Operations**: Use **`@Modifying`** with `@Query` for updates/deletes to bypass EntityManager overhead.
- **Connection Pool**: Configure **`HikariCP`** with explicit `maximum-pool-size`. Tune Hikari pool-size based on expected concurrent queries.

## Anti-Patterns

- **No N+1 Selects**: Use **`JOIN FETCH`** or **`@EntityGraph`** instead of lazy-loading in loops.
- **Entity Inflation**: Don't use `@Data` (Lombok) on Entities as it breaks Proxy and `hashCode`/`equals` performance.
- **Transactional Leak**: Don't put `@Transactional` on public `Repository` methods if `Service` already transactional.
- **Raw SQL**: Avoid native SQL unless JPQL/Criteria API insufficient.

## References

- [Implementation Examples](references/implementation.md)

Files in this skill

  • SKILL.md2.1 KB
  • evals/evals.json1.9 KB
  • references/implementation.md1.7 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.