# Hibernate Debugger

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com/help/idea/2026.3/llms.txt).

[Install the Hibernate Debugger plugin](jetbrains://tool/plugin/install?id=com.intellij.hibernate.debugger&tool=IU)

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](hibernate.html) 6 or later, either directly or through a framework like [Spring](spring-support.html).

![Hibernate Debugger log entry in a running Spring debugger session](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring.png)

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.

> **Note:**
> This topic describes only the features specific to the Hibernate Debugger. To learn about the framework-agnostic debugger features, refer to [Debug code](debugging-code.html).

## Prerequisites

* The following plugins are installed and enabled: * [Hibernate Debugger](https://plugins.jetbrains.com/plugin/34028) * [Jakarta EE: Persistence (JPA)](https://plugins.jetbrains.com/plugin/20202) (bundled) * Database Tools and SQL (bundled) To check if the plugins are enabled, open Settings (`Ctrl+Alt+S` (Windows), `⌘ Comma` (macOS), `⌘ Comma` (IntelliJ IDEA Classic (macOS)), `⌘ Comma` (macOS System Shortcuts), `Ctrl+Alt+S` (XWin), `Ctrl+Alt+S` (GNOME), `Ctrl+Alt+S` (KDE), `Ctrl+Alt+S` (Emacs), `Ctrl+Alt+S` (Sublime Text), `⌘ Comma` (Sublime Text (macOS)), `Ctrl+Alt+S` (Visual Studio), `⌘ Comma` (Visual Studio (macOS)), `Ctrl+Alt+S` (NetBeans), `Ctrl+Alt+S` (Eclipse), `⌘ Comma` (Eclipse (macOS))) and go to Plugins. [Open in the IDE](jetbrains://tool/settings?name=Plugins&tool=IU)

* Your build file (`pom.xml` or `build.gradle`) includes Hibernate 6 or later. Common ways to add it include: * ![Spring framework logo](https://resources.jetbrains.com/help/img/idea/2026.3/spring.icons.expui.spring.svg) Spring Boot starter: `spring-boot-starter-data-jpa` from Spring Boot version 3.0 or later [Learn how to add starters to your Spring Boot project.](spring-boot.html#add-starter) * Direct dependency: `hibernate-core` version 6 or later [Learn how to add Hibernate to your project.](hibernate.html#add-to-existing-project)

## Log and inspect database queries

Hibernate Debugger works inside the [IntelliJ IDEA debugger](debugging-code.html). 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.

Procedure: Inspect a query with Hibernate Debugger

1. [Start a debugging session.](starting-the-debugger-session.html)

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

3. Go to the [Debug](debug-tool-window.html) 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](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring_collapsed_queries.png)

> **Tip:**
> The most recent log entries appear at the bottom of the console. To jump to them, click ![Scroll down icon](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.platform.icons.expui.general.scrollDown.svg) Scroll to End in the toolbar on the left.

5. Click a highlighted line to open the log entry.

![Expanded Hibernate Debugger log entry](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring.png)

To learn how to interpret log entries, refer to [Reference: Hibernate Debugger log entries](#hibernate-debugger-reference).

Procedure: 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](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.hibernate.debugger.ide.frontend.icons.sqlLog.svg) 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](#identify-nplusone-queries).

* 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.

Procedure: 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](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.hibernate.debugger.ide.frontend.icons.sqlLog.svg) 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](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring_nplusone_collapsed.png)

6. Click one of the highlighted lines to open its log entry and then expand its [Invocation stack](#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](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring_nplusone_expanded.png)

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.

> **Tip:**
> The N+1 query problem is often caused by the following coding patterns:
>
>
>
> * Running a query inside a loop
>
> * Using related data in a loop without fetching it in the first query
>
> * Fetching entities with `@ManyToOne` or `@OneToOne` associations without fetching those associations in the same query
>
> * Converting entities to JSON or DTOs together with related data that the first query did not fetch

Procedure: 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](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.hibernate.debugger.ide.frontend.icons.sqlLog.svg) 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](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring_stop_logging.png)

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](using-jpa-console.html) and SQL statements in a [query console](query-consoles.html).

> **Warning:**
> Changes made by rerunning HQL statements are committed automatically and cannot be rolled back. For SQL statements, this depends on the query console’s [transaction mode](configuring-database-connections.html#transaction-mode).

Procedure: 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](#inspect-debugger-logs) for the query you want to rerun.

2. Click ![Green triangle icon](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.platform.icons.expui.run.run.svg) 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](https://resources.jetbrains.com/help/img/idea/2026.3/rerun_query_jpa_console.png)

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.](using-jpa-console.html#jpa-console-reference)

2.  In the query toolbar, click ![Parameters icon](https://resources.jetbrains.com/help/img/idea/2026.3/app.expui.nodes.parameter.svg) 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` (Windows), `⌘ ⏎` (macOS), `⌘ ⏎` (IntelliJ IDEA Classic (macOS)), `⌘ ⏎` (macOS System Shortcuts), `Ctrl+Enter` (XWin), `Ctrl+Enter` (GNOME), `Ctrl+Enter` (KDE), `Ctrl+Enter` (Emacs), `Ctrl+Enter` (Sublime Text), `⌘ ⏎` (Sublime Text (macOS)), `Ctrl+Enter` (Visual Studio), `⌘ ⏎` (Visual Studio (macOS)), `Ctrl+Enter` (NetBeans), `Ctrl+Enter` (Eclipse), `⌘ ⏎` (Eclipse (macOS))  .

Procedure: 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](#inspect-debugger-logs) for the query you want to rerun.

2. Click ![Green triangle icon](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.platform.icons.expui.run.run.svg) Execute query next to the  SQL .

A database-specific query console executes the query and the [Services](services-tool-window.html#db-sessions) tool window displays its results.

![Results of a query rerun from a Hibernate Debugger log in the Services tool window](https://resources.jetbrains.com/help/img/idea/2026.3/rerun_query_query_console.png)

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` (Windows), `⌘ ⏎` (macOS), `⌘ ⏎` (IntelliJ IDEA Classic (macOS)), `⌘ ⏎` (macOS System Shortcuts), `Ctrl+Enter` (XWin), `Ctrl+Enter` (GNOME), `Ctrl+Enter` (KDE), `Ctrl+Enter` (Emacs), `Ctrl+Enter` (Sublime Text), `⌘ ⏎` (Sublime Text (macOS)), `Ctrl+Enter` (Visual Studio), `⌘ ⏎` (Visual Studio (macOS)), `Ctrl+Enter` (NetBeans), `Ctrl+Enter` (Eclipse), `⌘ ⏎` (Eclipse (macOS)) .

## 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](database-tool-window.html) 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.](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring_data_source.png)

Here are a few examples of how you can work with the [data sources](managing-data-sources.html) from your debugging session in IntelliJ IDEA:

* Look up, add, edit, or delete database records in the [data editor and viewer](data-editor-and-viewer.html).

* Execute queries against your database in a [query console](query-consoles.html) or the [JPA Console](using-jpa-console.html).

* Create entity classes for existing tables by [reverse engineering the database](reverse-engineering.html).

* Bring the database schema in line with your entity classes by generating [Flyway migrations](flyway.html) or [Liquibase changelogs](liquibase.html).

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.

Procedure: 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](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.platform.icons.expui.general.copy.svg) Duplicate`.

* Alternatively, press `Ctrl+D` (Windows), `⌘ D` (macOS), `⌘ D` (IntelliJ IDEA Classic (macOS)), `⌘ D` (macOS System Shortcuts), `Ctrl+D` (XWin), `Ctrl+D` (GNOME), `Ctrl+D` (KDE), `Meta+D` (Emacs), `Ctrl+Shift+D` (Sublime Text), `⌘ ⇧ D` (Sublime Text (macOS)), `Ctrl+D` (Visual Studio), `⌘ D` (Visual Studio (macOS)), `Ctrl+D` (NetBeans), `Ctrl+D` (Eclipse), `Ctrl+D` (Eclipse (macOS)).

4. The [Data Sources and Drivers](data-sources-and-drivers-dialog.html) 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](https://resources.jetbrains.com/help/img/idea/2026.3/hibernate_debugger_spring_reference.png)

A Hibernate Debugger log entry includes the following sections:

1.  [Header](#header)

2.  [Session ID](#session-id)

3.  [HQL statement](#hql-statement)

4.  [SQL statement](#sql-statement)

5.  [Invocation stack](#invocation-stack)

The plugin also adds a toolbar icon (6) to the debugger, ![Hibernate Debugger icon](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.hibernate.debugger.ide.frontend.icons.sqlLog.svg) [SQL Log Settings and Filters](#settings-and-filters), which lets you filter log entries and change how they are displayed.

### Header

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](https://docs.hibernate.org/orm/current/javadocs/org/hibernate/Transaction.html) 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](https://docs.hibernate.org/orm/current/javadocs/org/hibernate/Session.html) 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](https://jakarta.ee/learn/docs/jakartaee-tutorial/current/persist/persistence-criteria/persistence-criteria.html), but here it is always displayed as an HQL statement.

> **Note:**
> This section is not displayed for native SQL queries and for SQL that Hibernate executed separately from other queries (for example, when it lazily fetched related data after the original query).

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](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.platform.icons.expui.run.run.svg) Execute query icon lets you [rerun the HQL statement in the JPA Console](#rerun-HQL-query) with the same parameter values. If the icon has an error indicator (![Red X mark](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.platform.icons.expui.runConfigurations.invalidConfigurationLayer.svg)), 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.

> **Note:**
> Some HQL queries cause Hibernate to execute more than one SQL query (for example, a query to load entities and extra queries to eagerly fetch their related data). For the extra queries, this section is called Triggered by HQL and does not include parameter values or an icon to rerun the query.

### 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](https://resources.jetbrains.com/help/img/idea/2026.3/intellij.platform.icons.expui.run.run.svg) Execute query icon lets you [rerun the SQL statement in a query console](#rerun-SQL-query) 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:

```JAVA_STACKTRACE
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

```JAVA_STACKTRACE
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.      > **Note:** > This option affects all debugging sessions in the current project, including the ones that you start later.      For more information, refer to [Stop logging queries](#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](configure-the-sql-code-style.html) 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](#identify-nplusone-queries).     |
|  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.     |

