Using the Hibernate Query Language Editor

See Also

You can use the Hibernate Query Language (HQL) Editor to write, edit and execute HQL queries within the IDE. After you create and test the HQL query in the editor you can copy the query to the source code and mapping files. You can right-click in the query editor window to select, copy and paste queries.

The syntax of the HQL query language is very similar to the syntax used in SQL queries but HQL is fully object-oriented and can use objects and properties to represent SQL queries. The syntax of HQL queries is not dependent upon the database the queries are run against. The HQL queries are converted at runtime to the SQL query appropriate for the database. In addition to supporting standard clauses and aggregate functions, HQL also supports polymorphic queries and subqueries.

For more about Hibernate Query Language, see the following Hibernate documentation:

To create and execute a HQL statement or script:

  1. Expand the <default packages> node under the Source Packages node in the Projects window.
  2. Right-click the hibernate.cfg.xml configuration file and choose Run HQL Query to open the HQL Editor.
  3. Enter the HQL query in the top pane of the editor window.
  4. Click Run HQL (  Run SQL ) in the toolbar. Alternatively, you can right-click in the query editor window and choose Run HQL from the popup menu.

When you execute an HQL query, you see the result of the query in the bottom pane of the HQL editor window. The HQL query is executed against the database specified in the project's Hibernate configuration file (hibernate.cfg.xml) that is selected in the editor toolbar. You can click the SQL button above the bottom pane to view the SQL query that corresponds to your HQL query.

See Also
Creating the Hibernate Configuration File
Editing the Hibernate Configuration File
Adding Hibernate Support to a Project
About Hibernate Support

Legal Notices