Step 6. Using HQL Editor

In this step, we will review of HQL Editor. The HQL Editor provides the facility to define and execute an HQL query.

  1. In the DbXaminer view, select the HQL Editor tab (at the bottom of the view). (If the DbXaminer view is closed, you can open it by right-clicking on SalesDBConnection in the DbXplorer and selecting Show in DbXaminer.)
  2. Navigate to the workshop-hibernate-tutorial web application as shown below.

  3. When defining an HQL query in the HQL Editor, Workshop provides code completion for HQL keywords and the persistent entities by pressing CTRL+SPACE. Here, we will define an HQL SELECT query using the code completion facility. In HQL Editor, enter S and press CTRL+SPACE. It displays a list of HQL keywords starting with letter S.
  4. Select the keyword select keyword.
  5. Using the same code completion technique, enter the following query:

    select p.productid, p.code, p.name from Product as p
  6. Now, we have defined a HQL SELECT query. You can execute them by either clicking the Execute Query button or by using the hotkey, CTRL+ENTER.

  7. Add a WHERE clause to the query to get products having code starting with prefix AB. You can either use code completion or write manually. Run the query to get products data.

  8. Click the Generated SQL tab in HQL Editor. It displays native SQL built based on the defined HQL query.

Click one of the following arrows to navigate through the tutorial:


Still need help? Post a question on the Workshop newsgroup.