liveBook · Manning

Spring Data JPA

As explained in Troubleshooting Java, Second Edition

Spring Data JPA is a Spring-based library that provides repository abstractions for accessing relational data through Java Persistence API implementations.

Spring Data JPA provides repository abstractions that hide SQL behind Java interfaces. It derives queries from method names or JPQL, making application logic concise but executed queries harder to inspect. section 6.3.2

When a framework hides a slow or unexpected query, profile the JDBC boundary rather than searching the repository interface. VisualVM can capture SQL before it reaches the DBMS, allowing investigation in a SQL client. section 6.3.2

A practical investigation checks:

  • Which SQL statements does an endpoint actually send? section 6.3.2
  • How often does each repository operation produce a query? section 6.3.2
  • Can the captured statement be copied into a SQL client for performance analysis? section 6.3.2

A repository with hidden SQL

A ProductRepository extending JpaRepository<Product, Integer> contains no visible SQL. Profiling a products endpoint reveals two generated statements; Hibernate executes the second only once even when the repository method is called ten times. section 6.3.2

public interface ProductRepository 
    extends JpaRepository<Product, Integer> { 
}

Inspect the minimal repository interface that delegates query generation and persistence behavior to the framework. section 6.3.2

How Troubleshooting Java, Second Edition covers it

How deep it goes
Explains repository-based query generation and profiler interception, then stops short of repository implementation internals.
Examples
Uses a ProductRepository, a products endpoint, generated SQL, and repeated calls optimized to one execution.
What you can do after
Diagnose/debug with it by extracting generated SQL, checking execution counts, and testing suspicious queries in a SQL client.
How it connects
Connects Spring Data JPA with Java Persistence Query Language, Hibernate, JDBC, DBMSs, SQL clients, and VisualVM.

Also explained in

Compare how 2 books explain Spring Data JPA →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Troubleshooting Java, Second Edition. The section links point to the parts of the book it draws on.