We can't find the internet
Attempting to reconnect
Something went wrong!
Hang in there while we get back on track
Performance oriented Spring Data JPA & Hibernate by Maciej Walkowiak
Learn essential Spring Data JPA & Hibernate optimization techniques including fetch strategies, connection management, transaction handling, and query performance tuning.
-
Turn off
spring.jpa.open-in-viewby default in Spring Boot applications to prevent holding database connections open unnecessarily -
Change fetch type to LAZY for
@ManyToOneand@OneToManyrelationships instead of using default EAGER loading -
Use projections instead of fetching full entities when you only need specific fields, especially for read operations
-
Monitor database connection usage with tools like Flexy, P6Spy, or DataSource-proxy to detect connection leaks and diagnose N+1 query problems
-
Avoid occupying database connections during external service calls by structuring transactions appropriately
-
Use
@DynamicUpdateto only update changed columns instead of all columns when modifying entities -
Consider using Spring’s
TransactionTemplatefor fine-grained transaction control instead of@Transactionalwith nested transactions -
Implement proper connection pool sizing as the default of 10 connections can become a bottleneck
-
Use
getReference()instead offindById()when you only need entity references without needing to load data -
Be explicit about joins using
@EntityGraphor JPQL join fetch statements to avoid N+1 queries -
Consider using native SQL queries or JDBC for complex read operations where JPA mappings add unnecessary overhead