HQL

HQL Editor

An integrated HQL Editor is provided for HQL file types, associated by default to files with .hql extension.

For your convenience Hibero also provides an HQL Scratch Pad editor (File | Open HQL Scratch Pad Ctrl + Shift + O) which doesn't require a physical file, useful for quick prototyping of HQL queries.

The HQL Editor provides Syntax Highlighting, Braces Matcher, Auto-Completion, Code Navigation, Find Usages, Rename/Move/Safe Delete refactorings, Code Formating, Surround With, Code Folding and Error Highlighting.

Each HQL Editor includes a tabed pane with three tabs: Query Results shows the resuls of a query execution; Query Translator holds the translation to SQL; and Parameters shows the discovered query parameters.

HQL Editor

Apart of using the mouse to select the visible tab, you may use the following actions:

  • Window | HQL Editor | Show HQL Query Results View Alt + Shift + R
  • Window | HQL Editor | Show HQL Query Translator View Alt + Shift + T
  • Window | HQL Editor | Show HQL Query Parameters View Alt + Shift + P

HQL Query Execution

At any moment the user may decide to run (Run | Run HQL Query Ctrl + F10) the HQL query being edited and the returned results, if any, will be shown in the embedded Query Results panel at the botton of the HQL Editor.
Both DDL and DML queries are supported.

HQL Query Execution Results

The results table is sortable and the column resize strategy is user customizable, as well as whether to use an scrollable result set (JDBC driver and HQL query permitting) or a fixed list size. See the Settings section of the documentation for details.

HQL Query Translation

The HQL Editor also provides a Query Translator panel which holds the translation of the HQL query to SQL as it is generated by Hibernate.

The translation to SQL can be set up to be done dynamically as the HQL query is edited or on demand (Edit | Translate HQL Query Ctrl + Shift + T).

HQL Query Translator

Parameters Auto-Discovery

The Parameters panel of the HQL Editor shows a table with all the parameters of the HQL query. This table displays the parameter position or name (for positional-style or EJBQL-style respectively), parameter type, and the value currently assigned to the parameter.

The same as with the HQL Query Translation, the discovery of parameters can be set up to be done dynamically as the query is edited or on demand (Edit | Discover HQL Parameters Ctrl + Shift + P).

Positional HQL Parameters

Named HQL Parameters

The number of parameters, their position/name, and type is automatically discovered by Hibero, and the user only needs to assign the values (only for Hibernate 3.1.x or above, if Hibernate 3.0.x or 2.x is used then the type needs to be specified manually by the user).

Unknown HQL Parameters Type

Inline Parameter Editor

The HQL Editor also features a convenient inline parameter editor to quickly assign a value to a parameter. To use this feature position the caret at the desired parameter and press Alt + Insert (or click the mouse over the light bulb) and select 'Set parameter value' intention.

Inline HQL Parameter Editor Intention

Inline HQL Parameter Editor

Show Parameter Info

Another convenient feature of the HQL Editor is the ability to show all the relevant information about a parameter (position/name, type and value) with the help of the View | Parameter Info action.

To use this feature, either move the caret to the desired parameter and press Ctrl + P, or hover the mouse over any discovered parameter.

Show HQL Parameter Info

Autoscroll from/to Parameter

Autoscroll from/to Parameter helps the user to visually map the parameters between the query code and the parameters table.

If Autoscroll from Parameter is selected then moving the caret to any parameter in the HQL code will select that parameter in the table.

If Autoscroll to Parameter is selected then selecting a parameter in the table will highlight that parameter in the HQL code.

Autoscroll from/to HQL Parameter

Quick HQL Query Edition

For those cases that you don't want to create a separate HQL file to edit a query Hibero provides a handy quick editor (View | Quick HQL Query Edition) available for Java string literals and named queries (i.e., HQL queries defined at XML mapping files or @javax.persitence.NamedQuery annotations).

Quick HQL Edition

This quick editor has exactly the same features as the standard HQL Editor, plus the option to cancel (Esc) any changes made to the query or to apply (Ctrl + Shift + X) such changes to the original query text.

Quick HQL Query Translation

If you just want to quickly see the translated SQL code for any given HQL query expressed in a Java string literal or named query then use the View | Quick HQL Query Translation action.

Quick HQL Translation

Quick HQL Query Execution

Java string literals and named queries can even be executed on-the-fly with the help of the View | Quick HQL Query Execution action.

Quick HQL Execution

Create HQL File Intention

Create a new HQL file out of a Java string literal or named query.

Create HQL File Intention