What is it about?

Most Java apps don't write SQL directly — frameworks like Hibernate or Spring Data JPA generate it. That convenience hides a common bug: fetching a list of orders correctly in one query, then firing one more query per order to get its details. It's called the N+1 query problem, and it's one of the most common causes of slow database-backed applications. Existing tools either just log queries without judging whether they're a problem, or only catch this inside unit tests, tied to one specific ORM, and often misfire on normal patterns like paginated lists or polling. Query Analyzer instead watches queries at the JDBC driver level, so the same detector works across Hibernate, Spring Data JPA, MyBatis, jOOQ, or raw JDBC — and it runs both in tests, as a JUnit check that fails a build before the bug ships, and in a live app, as a per-endpoint report. It scores each case by confidence rather than a raw count, so pagination, polling, and batched reads don't get flagged by mistake. Added to the unmodified Spring PetClinic sample app with one dependency and no code changes, it found three real N+1 bugs and raised no false alarms on the legitimate repeated queries on those same pages; applying its own suggested fix removed all three. On a controlled test suite it told true N+1s apart from look-alikes with no errors at all, where a simple repeated-query counter and an existing open-source detector both got it wrong.

Featured Image

Why is it important?

Two things set this apart from prior N+1 tools. First, it works at the JDBC layer instead of hooking into one ORM, so the same detector runs unmodified across Hibernate, Spring Data JPA, MyBatis, jOOQ, and raw JDBC — existing test-time tools are Hibernate-specific and only run in tests. Second, it tells a real N+1 apart from a merely repeated query (pagination, polling, batched reads) using a confidence model instead of a raw count, which is exactly where count-based tools misfire. Dropped into an unmodified real application with a single added dependency, it found three genuine bugs with zero false positives on the same pages, and its own suggested fix removed them — that's the bar that matters for a team deciding whether to trust an automated check in CI.

Perspectives

N+1 queries are the kind of bug that's easy to introduce and easy to miss in review — the code looks completely normal until you look at the query log. The tools I found were either too narrow (built for one ORM, only usable in tests) or too noisy (flag any repeated query, including perfectly normal ones like a paginated list), which is probably why teams end up not using them at all. I wanted something that behaved the same way regardless of which ORM a project uses, and that was precise enough to actually trust in CI without a human double-checking every alert.

Mahmoud khawaja
Cairo University

Read the Original

This page is a summary of: Query Analyzer: Framework-Agnostic, Confidence-Based N+1 Detection for the JVM, October 2026, ACM (Association for Computing Machinery),
DOI: 10.1145/3837729.3840484.
You can read the full text:

Read

Contributors

The following have contributed to this page