llms.txt: machine-readable documentation index. Markdown version of this page is also available.

IntelliJ IDEA 2026.3 Help

Hibernate Debugger

Install the Hibernate Debugger plugin

Hibernate Debugger is an IntelliJ IDEA plugin that lets you inspect database queries run in your application and trace them back to where your code triggers them. It works with applications that use Hibernate 6 or later, either directly or through a framework like Spring.

Hibernate Debugger log entry in a running Spring debugger session

You can use Hibernate Debugger to perform the following debugging tasks:

  • Check what HQL statements a particular operation triggers and what SQL Hibernate sends to the database as a result.

  • Find slow queries and potential N+1 problems.

  • Locate the code that triggered a particular query.

  • Rerun captured HQL and SQL in the IDE.

  • Explore the databases your application connects to.

Prerequisites

Log and inspect database queries

Hibernate Debugger works inside the IntelliJ IDEA debugger. Whenever your application runs a query through Hibernate during a debugging session, the plugin logs information about it in the debugger console. The log shows the executed SQL and any related HQL, along with runtime details such as the execution time, transaction ID, and the code that triggered the query.

Query logging is on by default.

Inspect a query with Hibernate Debugger

  1. Start a debugging session.

  2. In your application, perform an action that interacts with a database.

  3. Go to the Debug tool window and open the Console tab.

  4. Find the Hibernate Debugger log entries for the action you performed. Each entry is collapsed into a single highlighted line and shows the executed SQL statement.

    Rows with Hibernate Debugger entries highlighted in the Console tab of the Debug tool window
  5. Click a highlighted line to open the log entry.

    Expanded Hibernate Debugger log entry

To learn how to interpret log entries, refer to Reference: Hibernate Debugger log entries.

Filter logged queries

  1. While the debugging session is running, go to the Debug tool window and open the Console tab.

  2. In the debugger toolbar, click Hibernate Debugger icon SQL Log Settings and Filters.

  3. Select one or more filters:

    • Show only suspected N+1 queries: display only the queries from transactions that are suspected to have an N+1 problem. You can then trace their origin in code.

    • Filter by duration: specify the minimum duration in milliseconds to display only the queries that took this amount of time or longer to execute.

    • Filter by transaction: specify the transaction ID to display only the queries that were executed in this transaction.

If you select several filters, only the log entries that match all of them are displayed. The filters apply to the current debugging session and are cleared when you close the session tab.

Identify N+1 queries and trace their origin in code

The N+1 query problem is a common performance issue in applications that use object-relational mapping (ORM) frameworks. It occurs when an application runs one query to fetch a list of records and then a separate query to fetch related data for each record.

Hibernate Debugger detects transactions with potential N+1 queries and lets you filter out queries from other transactions.

  1. Start a debugging session.

  2. In your application, invoke the actions that you want to check for N+1 queries.

  3. Go to the Debug tool window and open the Console tab.

  4. In the debugger toolbar, click Hibernate Debugger icon SQL Log Settings and Filters and select Show only suspected N+1 queries.

  5. Look for highlighted lines that share the same transaction ID and SQL query.

    Highlighted Hibernate Debugger log entries with the same transaction ID and SQL query after filtering for suspected N+1 queries
  6. Click one of the highlighted lines to open its log entry and then expand its Invocation stack section. It contains the sequence of method calls that led to the repeated query's execution.

    Suspected N+1 query's Invocation stack section is expanded in the Debug tool window
  7. Locate the top stack line that ends with a file name and line number from your project code (not library or framework-generated code) and click them.

IntelliJ IDEA opens the file at the line where your code triggered the query. Examine the method, its surrounding code, and the methods that call it to find out why the query runs repeatedly.

Stop logging queries

  1. While the debugging session is running, go to the Debug tool window.

  2. In the debugger toolbar, click Hibernate Debugger icon SQL Log Settings and Filters and clear the Log database queries option.

    Log database queries option cleared in the Hibernate Debugger SQL Log Settings and Filters box

Turning off query logging applies to all debugging sessions in the project. You can turn it back on at any time by selecting Log database queries again.

Rerun captured queries

You can rerun queries captured by Hibernate Debugger without having to trigger them again in your application. HQL statements are rerun in the JPA Console and SQL statements in a query console.

Rerun an HQL query

Rerunning HQL can be useful when, for example, you want to check which records a query fetches, compare its results before and after your application commits changes to the database, or run it separately from other queries in a sequence.

  1. Open the Hibernate Debugger log entry for the query you want to rerun.

  2. Click Green triangle icon Execute query next to the HQL. If some parameter values cannot be restored, you will be prompted to specify them.

    The JPA Console executes the query and displays its results.

    Results of a query rerun from a Hibernate Debugger log in the JPA Console
  3. (Optional) Rerun the query with different parameter values:

    1. Switch from the result tab to the console tab.

      Learn more about the JPA Console layout.

    2. In the query toolbar, click Parameters icon View Parameters. This opens a pane with parameter values on the right side of the console.

    3. Edit the parameter values and rerun the query by pressing Ctrl+Enter.

Rerun an SQL query

Rerunning SQL can be useful when, for example, you want to check which records Hibernate fetches during lazy loading or how long a slow query takes when it runs directly against the database.

  1. Open the Hibernate Debugger log entry for the query you want to rerun.

  2. Click Green triangle icon Execute query next to the SQL.

    A database-specific query console executes the query and the Services tool window displays its results.

    Results of a query rerun from a Hibernate Debugger log in the Services tool window
  3. (Optional) Rerun the query with different parameter values:

    1. In the editor, go to the query console tab that IntelliJ IDEA opened. The SQL query is already there with its original parameter values.

    2. Edit the parameter values and rerun the query by pressing Ctrl+Enter.

Access the database while debugging

When a query result does not match what you expect, the cause may not be in the code, but in the data. To help you examine both, Hibernate Debugger adds database connections from your debugging session to the Database tool window.

Database tool window displays a data source added during a debugger session. The top node in the tool window shows the run configuration name and the data source itself has a debug note in square brackets.

Here are a few examples of how you can work with the data sources from your debugging session in IntelliJ IDEA:

Data sources created by Hibernate Debugger are removed when the debugging session ends. To keep a data source permanently, create a copy of it while the session is still running.

Keep a data source after the debugging session ends

  1. While the debugging session is running, go to the Database tool window.

  2. Find the folder named after your debugging session and select the data source you want to keep.

  3. Right-click the data source and select Copy/Paste | Copy icon Duplicate.

    • Alternatively, press Ctrl+D.

  4. The Data Sources and Drivers dialog opens. If needed, rename the data source or adjust its connection details.

  5. Click OK to save the copy.

  6. The copied data source is placed in the same folder as the original. To prevent the copy from being removed, right-click it and select Move | To Top Level.

Reference: Hibernate Debugger log entries

Image of Hibernate debugger log entries with frames marking different parts that make up the log

A Hibernate Debugger log entry includes the following sections:

  1. Header

  2. Session ID

  3. HQL statement

  4. SQL statement

  5. Invocation stack

The plugin also adds a toolbar icon (6) to the debugger, Hibernate Debugger icon SQL Log Settings and Filters, which lets you filter log entries and change how they are displayed.

The log entry header includes the following information:

  1. Timestamp when Hibernate Debugger captured the query. It uses the local time in the ISO 8601 format with the UTC offset.

  2. Time that it took to execute the query.

  3. ID of the Hibernate transaction in which the query was executed. This value is assigned by the debugger. A dash means that Hibernate Debugger could not find out which transaction the query belongs to.

    You can filter the log entries to only display queries from this transaction by clicking the ID and selecting Filter by this transaction.

Session ID

This ID identifies the Hibernate session that sent the query to the database. It is assigned by Hibernate.

A dash means that Hibernate Debugger could not find out which session sent the query.

HQL statement

This is the query that your application handed to Hibernate and that Hibernate turned into the SQL statement below. In your code, the query can come from a repository method, a query string (HQL, JPQL, JDQL), or the Jakarta Persistence Criteria API, but here it is always displayed as an HQL statement.

If the HQL contains parameters, their values are listed on a separate line in one of the following formats:

  • name: Type = value: named parameter

  • ?1: Type = value: positional parameter

  • __param_0: Type = value: generated parameter (for example, derived from a repository method name)

  • ?unknown: Type = value: parameter whose name could not be determined

  • name: <unbound>: parameter that had no value when the HQL was executed

The Green triangle icon Execute query icon lets you rerun the HQL statement in the JPA Console with the same parameter values. If the icon has an error indicator (Red X mark), it means that some parameter values cannot be passed to the console. In this case, the console will prompt you to enter the missing values before rerunning the HQL.

SQL statement

This is the SQL statement that Hibernate sent to the database. It can be translated by Hibernate from the HQL above it, generated by Hibernate on its own, or written in your code as a native SQL query.

If the statement contains parameters, their values are displayed within the statement.

The Green triangle icon Execute query icon lets you rerun the SQL statement in a query console with the same parameter values.

Invocation stack

The invocation stack shows the method calls that led to Hibernate sending the SQL statement to the database. Like in any Java stack trace, the most recent call is at the top. Calls in library code (such as Hibernate or Spring) are collapsed by default.

Each line in the invocation stack represents one method call. For example, consider this simplified stack:

at com.example.library.BookRepository.findByTitle(BookRepository.java:31) at com.example.library.BookService.searchBooks(BookService.java:24) at com.example.library.BookController.listBooks(BookController.java:18)

The highlighted line represents a call to searchBooks(). The example stack provides the following details about it:

  • searchBooks() was called by BookController.listBooks().

  • It is declared in the BookService class, which belongs to the com.example.library package.

  • It is implemented in the BookService.java source file.

  • At line 24 of that file, it called BookRepository.findByTitle().

Most stack lines end with a file name and line number that show where this method called the next one. You can click them to navigate to that call in the editor. If a line ends with Unknown Source or <generated> instead, the call was usually made from code that a framework generated directly in compiled form, so there is no source file for it.

Example from a Spring Data JPA application

Invocation stack: <36 hidden frames> at com.example.library.BookRepository.findByTitle(Unknown Source) at com.example.library.BookService.searchBooks(BookService.java:24) <14 hidden frames> at com.example.library.BookService$$SpringCGLIB$$0.searchBooks(<generated>) at com.example.library.BookController.listBooks(BookController.java:18) <53 hidden frames>

In this example, the call sequence is as follows (read from the bottom up):

  1. A chain of calls in library code (collapsed into <53 hidden frames>) resulted in a call to BookController.listBooks() in the project code.

  2. BookController.listBooks() called BookService.searchBooks().

    1. The call went to BookService$$SpringCGLIB$$0. This is a proxy generated by Spring at runtime, so <generated> is displayed instead of the file name.

    2. The proxy started a chain of calls in Spring library code (collapsed into <14 hidden frames>) that resulted in a call to BookService.searchBooks().

  3. BookService.searchBooks() called BookRepository.findByTitle().

    The call went to the method's implementation provided by Spring Data. This implementation was generated at runtime, so Unknown Source is displayed instead of the file name.

  4. The implementation of findByTitle() started a chain of calls in Spring and Hibernate library code (collapsed into <36 hidden frames>) that resulted in Hibernate sending the SQL statement to the database.

Settings and filters

Item

Description

Log database queries

Turn query logging on or off.

For more information, refer to Stop logging queries.

Format statements

Change how statements are displayed in the debugger console:

  • For HQL statements, this moves each clause (such as select, from, or where) to a new line and replaces generated aliases with the entity's first letter.

  • For SQL statements, this applies the SQL code style configured in the IDE.

Show only suspected N+1 queries

Display only the queries from transactions that are suspected to have an N+1 problem, meaning that the same query is executed repeatedly.

For more information, refer to Identify N+1 queries and trace their origin in code.

Filter by duration

Specify the minimum duration in milliseconds to display only the queries that took this amount of time or longer to execute.

Filter by transaction

Specify the transaction ID to display only the queries that were executed in this transaction.

27 October 2026