JDBC profiling intercepts database activity from a Java application. It can reveal the SQL a persistence framework generates or show whether database connections are opened and closed correctly. section 7.3.3 section 8.1
Use the observations to narrow down the problem:
- Inspect intercepted SQL for unexpected joins. A second CriteriaQuery.from() call created an unnecessary cross join; reusing the existing product root removed it. section 7.3.3
- Inspect connection status after reproducing the issue. Connections still open long after a request responds can indicate a leak; CPU profiling can provide a stack trace to the creating code. section 8.1
- After changing the code, profile again to check the result. Correcting the connection leak stopped the connections from remaining open. section 8.1
Figure 7.14 The profiler can intercept any SQL query sent to the DBMS through the JDBC driver. Here, we spot an issue in the generated query—an unneeded cross join that causes performance problems.
The intercepted SQL makes the unnecessary cross join visible. section 7.3.3
A query that looks harmless on a small table
A criteria query for one product accidentally adds a second root. With only ten records, the cross join may look harmless; with larger tables, it can cause latency and duplicate rows. section 7.3.3
