{"enrichment":{"faq":[{"a":"jpa-patterns addresses N+1 queries by teaching JOIN FETCH and EntityGraph strategies. The core issue: loading a parent entity triggers separate queries for each child. jpa-patterns shows how to use JOIN FETCH in JPQL queries to eagerly load relationships in a single query, or EntityGraph annotations to specify fetch plans declaratively. For Spring Data repositories, use @EntityGraph on custom query methods. Batch fetching via hibernate.default_batch_fetch_size also reduces round trips by loading multiple entities per query.","q":"How to fix N+1 query problem in JPA?"},{"a":"jpa-patterns explains that LazyInitializationException occurs when accessing a lazily-loaded relationship outside an active transaction or session. Common scenarios: returning entities from a service method after the transaction closes, or accessing lazy fields in a view layer. Solutions include: wrapping access in @Transactional, using JOIN FETCH to eagerly load needed relationships, converting to DTOs before transaction end, or enabling Open Session In View (though this can mask design issues). Choose based on your architecture.","q":"What causes LazyInitializationException in Spring Boot Hibernate?"},{"a":"jpa-patterns teaches that LAZY is the safer default: it loads data only when accessed, reducing memory and query overhead. Use LAZY for relationships you don't always need. Switch to EAGER only when a relationship is almost always accessed together with the parent\u2014but this risks loading unnecessary data. Better practice: keep relationships LAZY and use JOIN FETCH or EntityGraph in specific queries where you know you need them. This gives you explicit control and avoids hidden performance surprises.","q":"When should jpa-patterns recommend EAGER vs LAZY fetch strategies?"},{"a":"jpa-patterns covers Spring @Transactional configuration, propagation levels, and isolation settings for safe concurrent access. For preventing lost updates, it demonstrates optimistic locking via @Version fields: JPA increments the version on each update, and concurrent modifications fail with OptimisticLockException. Pessimistic locking with LockModeType.PESSIMISTIC_WRITE is also shown for high-contention scenarios. Proper transaction boundaries, cascade types, and dirty-checking behavior are explained to avoid common concurrency pitfalls.","q":"How does jpa-patterns handle transaction management and concurrency?"},{"a":"jpa-patterns contrasts these two eager-loading approaches: JOIN FETCH is a JPQL syntax that explicitly joins and fetches related entities in a single query\u2014simple but couples your query logic to fetch strategy. EntityGraph is a declarative annotation-based approach that specifies fetch plans separately from queries, allowing reuse across multiple query methods. EntityGraph is more flexible for complex entity graphs and repository-based queries, while JOIN FETCH gives finer control in custom JPQL. Choose based on whether you prefer query-level or metadata-level fetch definition.","q":"What's the difference between JOIN FETCH and EntityGraph in jpa-patterns?"},{"a":"jpa-patterns demonstrates Spring Data JPA pagination via Pageable parameters and PagingAndSortingRepository, which automatically handles limit/offset. For large result sets, it shows DTO projections: querying only needed columns instead of full entities reduces memory and serialization overhead. Use @Query with constructor expressions or interface-based projections. Bulk operations (updateQuery, deleteInBatch) bypass entity instantiation for mass changes. Combined with proper indexing and fetch strategies, these techniques significantly improve throughput on large datasets.","q":"How can jpa-patterns help optimize queries with pagination and projections?"}],"shadow_tags":["query-performance","lazy-loading-errors","transaction-scope","entity-mapping","concurrency-control","data-fetching","orm-patterns","spring-persistence"],"summary_rewrite":"This skill addresses the most common JPA performance bottlenecks: N+1 query problems, lazy loading errors, and transaction misconfigurations. It covers practical solutions like JOIN FETCH and EntityGraph for efficient data fetching, explains when to use LAZY vs EAGER loading, and demonstrates transaction management best practices for Spring applications."},"files":[{"bytes":16054,"path":".claude/skills/jpa-patterns/SKILL.md","sha256":"06cfa8595b38339586af630122f4257c0ec1f4e7448af54a5bf01ffcabf87b40","url":"https://skillfed.io/files/decebals/claude-code-java/jpa-patterns/69679bee/SKILL.md"}],"id":"decebals/claude-code-java/jpa-patterns","links":{"html":"https://skillfed.io/decebals/claude-code-java/jpa-patterns","md":"https://skillfed.io/decebals/claude-code-java/jpa-patterns.md","repo":"https://github.com/decebals/claude-code-java"},"meta":{"agents_supported":["claude-code"],"first_seen":"2026-07-28","forks":135,"language":"Shell","last_updated":"2026-02-08","license":"MIT","name":"jpa-patterns","publisher":"decebals","stars":693},"relations":{"similar":[{"id":"pluginagentmarketplace/custom-plugin-java/java-jpa-hibernate"},{"id":"xu-xiang/everything-claude-code-zh/jpa-patterns"},{"id":"rohitg00/awesome-claude-code-toolkit/springboot-patterns"},{"id":"giuseppe-trisciuoglio/developer-kit/spring-data-jpa"},{"id":"affaan-m/ECC/jpa-patterns"},{"id":"manutej/luxor-claude-marketplace/spring-boot-development"},{"id":"personamanagmentlayer/pcl/spring-boot-expert"},{"id":"bobmatnyc/claude-mpm-skills/spring-boot"},{"id":"Kotlin/kotlin-agent-skills/kotlin-backend-jpa-entity-mapping"},{"id":"neo4j-contrib/neo4j-skills/neo4j-spring-data-skill"}]},"slug":{"owner":"decebals","repo":"claude-code-java","skill":"jpa-patterns"},"version":"69679bee"}
