Works with the AI tools you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+22 more

    JPA N+1 Query Smell Detector

    1

    Static analysis skill to detect and fix JPA N+1 queries, fetch join errors, and Hibernate smells in Spring Boot.

    Free

    Security scanned
    JPA N+1 Query Smell Detector

    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

    SeverityIDLocationFindingFix Suggestion
    P0N1-01OrderService.java:142Lazy items collection accessed inside a forEach loop without a fetch strategy.Add JOIN FETCH o.items to the query in OrderRepository.
    P0N1-02CustomerController.java:45Customer 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.
    P1N1-04OrderRepository.java:28Using 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

    1. Apply the JOIN FETCH fix to OrderRepository.
    2. Introduce a CustomerResponse DTO to decouple the web layer from the database schema.
    3. Review OrderRepository pagination to prevent HHH000104 warnings 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 @Entity definitions 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

    1. Map entities by scanning for @Entity annotations and recording all LAZY relationships.
    2. Trace usage by searching for those relationships within loops, MapStruct mappers, or controller return types.
    3. Audit queries at the repository level to see if fetch joins are missing where they are needed.
    4. 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

    Listed2 days ago

    What's inside

    Frequently Asked Questions