Optimize JPA, Hibernate, and database interactions in Spring Boot. Use when implementing JPA entities, repositories, or database access in Spring Boot. (triggers: **/*Repository.java, **/*Entity.java, jpa-repository, entity-graph, transactional, n-plus-1)
@Transactional(readOnly = true) on Services to optimize DB resources.Java Records for Read-Only query results. Avoid fetching full @Entity objects when not necessary.Pageable and Slice (or Page) to prevent loading massive datasets.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 for repository projections, EntityGraph, and transactional patterns.
N+1 selects using JOIN FETCH (JPQL) or @EntityGraph.spring.jpa.open-in-view=false in application.yaml.@Modifying with @Query for updates/deletes to bypass EntityManager overhead.HikariCP with explicit maximum-pool-size. Tune Hikari pool-size based on expected concurrent queries.JOIN FETCH or @EntityGraph instead of lazy-loading in loops.@Data (Lombok) on Entities as it breaks Proxy and hashCode/equals performance.@Transactional on public Repository methods if Service already transactional.