IntelliJ IDEA 2020.3 Help

Hibernate console

Use the Hibernate console to write and run HQL queries. It provides useful highlighting and completion for JPQL keywords, object and property names.

Open the Hibernate console

  • In the Persistence tool window, right-click a session factory or entity and select Console. Alternatively, you can click The Console button in the toolbar or press Ctrl+Shift+F10.

The Hibernate console input pane opens as a separate tab where you can write and execute HQL queries.

The Hibernate console toolbar contains the following buttons:

Execute Query Ctrl+Enter Run the current query.
Generate Script

Generate an SQL statement or a DDL script.

  • Ctrl+Shift+Enter Generate SQL: Generate an SQL equivalent of the current JPQL statement.

  • Ctrl+Alt+Shift+Enter Generate DDL: Generate the corresponding CREATE TABLE, ALTER TABLE, and DROP TABLE statements for all the objects (classes) associated with the current persistence unit.

Open Database Settings Open the Database page of the Settings/Preferences dialog Ctrl+Alt+S.
View Parameters Open the Parameters pane to see the parameters used in your queries and set their values.
Browse Query History Ctrl+Alt+E Open the console history dialog that shows all the queries that you have run in this console.
Restore Default Layout Restore the original tool window layout after layout changes.
Select Properties Source Select the source for properties.
Terminate Process Ctrl+F2 Terminate the current console session.
Close Ctrl+Shift+F4 Close the current console.

Run HQL queries

After you write a query, do one of the following:

  • Press Ctrl+Enter.

  • Click The Execute Query button in the toolbar.

When you execute a query with parameters, you will need to enter their values. Alternatively, click The View Parameters button to open the Parameters pane.

IntelliJ IDEA stores all queries that you execute. Press Up to see the previously executed commands, starting from the most recent one. To see the full history, press The Browse Query History button.

Run the Hibernate console with custom JVM options

The Hibernate console is a Java process. If necessary, you can start it with custom JVM options:

  1. Create an Application run configuration

    From the main menu, select Run | Edit Configurations, click the Add button, and select Application.

  2. In the VM options field, specify the options that you want to pass to the JVM when it starts. The rest of the run configuration settings don't matter and you don't need to specify them.

    Click OK to save the run configuration.

  3. When you open the Hibernate console, IntelliJ IDEA will display an additional VM and Env Configuration popup with the available run configurations. Select the one with the necessary JVM options or run with the default settings.

Last modified: 15 January 2021