In this step, we will take an overview of HQL Editor. The HQL Editor provides facility to define and execute an HQL query.
7.1. Using HQL Editor
In DbXaminer, go to the HQL Editor tab and click the button to choose the Workshop-Hibernate-Tutorial web application.
When defining an HQL query in HQL Editor, Workshop Studio 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.
Select the keyword select keyword.
Enter space and specify comma separated properties of Product object to get the data i.e. p.productid, p.code, p.name
as shown below. Note: the properties are prefixed by an alias p for Product entity.
Enter from (You can use code completion for from keyword) and space.
Press CTRL+SPACE to get a list of persistent entities and select the Product object.
Enter space and specify an alias p for Product entity.
Now, we have defined the HQL SELECT query. You can execute them by either clicking the Execute Query button or by using the hotkey, CTRL+ENTER.
Add HQL 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.
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: