- Home
- Skills
- APIs & Backend
- JPA N+1 Query Smell Detector
Works with the AI tools you already use
JPA N+1 Query Smell Detector
Static analysis skill to detect and fix JPA N+1 queries, fetch join errors, and Hibernate smells in Spring Boot.
Free
JPA N+1 Query Smell Detector
Example session with this skill installed
Scan the Order and Customer modules for N+1 query smells and Hibernate performance issues.
- Read your context and instructions
- Compiled the jpa n+1 query
I have analyzed the Order and Customer entities and their respective service layers. The scan identified 3 performance smells across 12 usage sites.
JPA Query Smell Report
| Severity | ID | Location | Finding | Fix Suggestion |
|---|---|---|---|---|
| P0 | N1-01 | OrderService.java:142 | Lazy items collection accessed inside a forEach loop without a fetch strategy. | Add JOIN FETCH o.items to the query in OrderRepository. |
| P0 | N1-02 | CustomerController.java:45 | Customer entity with lazy addresses returned directly in a REST controller, triggering Jackson serialization N+1. | Use a DTO projection or an @EntityGraph for the controller query. |
| P1 | N1-04 | OrderRepository.java:28 | Using JOIN FETCH on the items collection combined with a Pageable parameter, causing in-memory pagination. | Remove JOIN FETCH and use @BatchSize or a two-step query approach. |
Verification
To verify the P0 findings, enable SQL logging by adding logging.level.org.hibernate.SQL=DEBUG to your application.properties. Run the integration tests for these endpoints and confirm the query count does not increase linearly with the number of records.
Next steps
- Apply the
JOIN FETCHfix toOrderRepository. - Introduce a
CustomerResponseDTO to decouple the web layer from the database schema. - Review
OrderRepositorypagination to preventHHH000104warnings in production logs.
Scanned: 2 entities, 12 usage sites. 2 P0, 1 P1, 0 P2.
For the full production sweep see Spring Boot Production Readiness Review; for tenant isolation see Multi-Tenant SaaS Audit.
Connects securely to your tools. The creator never sees your data.
About this skill
Identifying JPA and Hibernate performance bottlenecks during development is difficult without running the application and monitoring logs. This skill performs static analysis on Spring Boot codebases to find N+1 query patterns and JPA smells before they hit production.
What it does
- Entity Mapping catalogs all
@Entitydefinitions and identifies potentially problematic LAZY associations. - Usage Analysis tracks where lazy fields are accessed in loops, streams, mappers, or Jackson serialization points.
- Fetch Strategy Audit checks if parent queries use
JOIN FETCH,@EntityGraph, or DTO projections to prevent extra roundtrips. - Severity Scoring classifies findings from P0 (critical N+1) to P2 (minor optimization) using a standardized smell reference.
- Fix Generation provides a one-sentence remediation and a verification method for every detected issue.
How it works
- Map entities by scanning for
@Entityannotations and recording all LAZY relationships. - Trace usage by searching for those relationships within loops, MapStruct mappers, or controller return types.
- Audit queries at the repository level to see if fetch joins are missing where they are needed.
- Generate report using the standardized P0-P2 format including file paths and line numbers.
Frameworks & tools
Built for Spring Boot, JPA, and Hibernate. Supports analysis of MapStruct, Jackson serialization, and standard Spring Data JPA repositories.
Why this beats prompting it yourself
Generic prompts often miss subtle N+1 triggers like Jackson serialization or MultipleBagFetchException risks. This skill uses a structured reference table to ensure every scan is consistent, systematic, and covers edge cases like pagination with fetch joins.
Use cases
- Scan a new PR for performance regressions before merging to main.
- Audit a legacy Spring Boot service that is experiencing slow database response times.
- Validate that junior developers are following proper JPA fetching strategies in complex domain models.
Known limitations
Static analysis only. It cannot detect dynamic query issues caused by reflection or runtime bytecode enhancement not visible in source code.
How to use
Skills on Agensi run inside your AI agent. Copy the prompt, paste it into your agent, and it connects to Agensi and installs this skill for you. If a payment is needed, your agent shows it to you first.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill passes our trust checks below.
Security scanned
Passed our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scanned
Verified clean 2 days ago
- Free to download with an account