HQL Query Objects in Hibernate

HQL Query Objects in Hibernate
In our previous hibernate article, we have seen CRUD Operations. Similar to SQL Queries, Hibernate uses a Language called HQL – Hibernate Query Language. This is almost similar to SQL, But here instead of Table name we use Entity name and instead of Column name we use Entity properties name.

Once we are through this code, we can understand HQL.

Lets see an example code of using Query Objects in Hibernate. For the purpose of example, I have created a Table with name Student_Table and populated with some values.

Table 1

In this below example, we are going to use Query Object and HQL to list sname from above table.






In the above code, we have used “from Student” –> This code is similar to SQL query – Select * from Student_Table
Note that, We have not used table name instead we have used Entity name ‘Student’. In HQL, Instead of Table name we always use Entity name.



Leave a Reply

Your email address will not be published. Required fields are marked *