Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 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

    1 useSecurity 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.

    Static analysis only. Cannot detect dynamic query issues caused by reflection or runtime bytecode enhancement. Requires source code access to entities and repositories.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before any payment.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    1 use

    Times used to date

    Free forever

    No account required to browse

    Trust & safety

    Security scan

    Security scan passed 1 month ago

    • Free with an Agensi account

    Permissions

    Read Files
    Terminal / Shell
    Listed1 month ago

    What's inside

    Frequently Asked Questions

    This skill identifies N+1 query patterns by tracing LAZY association access within loops, mappers, and serialization points, allowing you to fix performance bottlenecks during development rather than after a production slowdown.

    It is specifically designed for Spring Boot applications using JPA/Hibernate and provides out-of-the-box analysis for MapStruct and Jackson serialization risks.

    Yes, the skill categorizes findings into P0 to P2 severity levels, providing both a remediation strategy and a verification method for each detected smell.

    The skill focuses on static analysis of your source code and repository patterns, meaning it does not require a live database connection or runtime profiler to operate.

    Your purchase includes the core JPA analysis logic, a structured smell reference table for consistent reporting, and any future logic updates released for this version.

    New in APIs & Backend