IntelliJ IDEA 12.1.0 Web Help

Some features described here are available in Ultimate edition only.

IntelliJ IDEA provides HQL support and enables creating queries in the Hibernate Console dedicated tool window. The console is started using the run configuration of the type Query Language Console.

You can have several instances of the Hibernate console running simultaneously. Each console is opened in a separate tab of the tool window. Each tab shows the name of the session factory from which the console is launched.

In the Hibernate console, you can explore the data sources configured in your workspace, create and run queries, and generate DDL or SQL scripts based on HQL commands. The console is aware of the HQL syntax and provides coding assistance.

To launch the hibernate console
  1. In the Persistence tool window, expand the Hibernate Facets node and select the desired session factory.
  2. On the context menu, choose Open Query Console or click runJdbcConsole.png.
  3. In the Choose Console pop-up window, do one of the following:
    • To launch a console, choose Hibernate Console from the Open New list.
    • To open an already running HQL console, choose the name of the desired console from the Running list.
    openJPAConsole
To execute queries from the hibernate console, perform the following general steps
  • Type the desired commands in the upper section of the console. Note syntax and error highlighting, code completion, intention actions, and quick fixes.

    hqlConsole.png

  • To start a new line, press EnterEnterEnterEnterEnterEnterEnterEnterEnterEnterEnterEnter.
  • Use the basic and advanced editor shortcuts. In particular, you can jump to declaration of a table or its column in the corresponding Java class, if you place the caret at the table or column name, and press Ctrl+B, Ctrl+Button1 Click or Button2 ClickCtrl+B, Ctrl+Button1 Click or Button2 ClickCtrl+B, Ctrl+Button1 Click or Button2 ClickCtrl+B, Ctrl+Button1 Click or Button2 ClickCtrl+Alt+G, Escape, Period, Alt+Period or Ctrl+Button1 ClickCtrl+B, Ctrl+Button1 Click or Button2 ClickF12, Shift+F2, Ctrl+B, Ctrl+Button1 Click or Button2 ClickCtrl+B, Ctrl+Button1 Click or Button2 ClickF3 or Ctrl+Button1 ClickMeta B, Meta Button1 Click or Button2 ClickMeta B, Meta Button1 Click or Button2 ClickF3 or Control Button1 Click. Alternatively, keep the Ctrl key pressed, and hover your mouse pointer over the reference to a table or column. So doing the reference turns to a hyperlink, which allows you to jump to the declaration in the source code:

    hqlConsole1.png

  • To run the commands, click the runBuild.gif button on the toolbar or press Ctrl+EnterCtrl+EnterCtrl+EnterCtrl+EnterCtrl+EnterCtrl+EnterCtrl+EnterCtrl+EnterCtrl+EnterMeta EnterMeta EnterMeta Enter.
  • View the query execution result in the Result tab.
  • View and analyze information messages and query execution details in the Output tab.
To generate scripts, perform the following general steps
  • To have IntelliJ IDEA generate an SQL script from a HQL command, type the query and click the Generate SQL toolbar button icon_generateSQL.png.
  • To have a DDL script generated based on the Hibernate configuration for which the console has been launched, click the Generate DDL toolbar button icon_generateDDL.png.

See Also

Procedures:

Reference:

Web Resources: