Junior — Middle
What role does Hibernate Query Language play in working with databases?
sobes.tech AI
Answer from AI
Hibernate Query Language (HQL) is an object-oriented query language used in Hibernate to interact with the database. Unlike SQL, which works with tables and columns, HQL operates on objects and their properties, allowing for queries that are independent of a specific database.
Role of HQL:
- Enables executing queries on the database using object-oriented concepts.
- Automatically converts queries into SQL, considering the specifics of the particular DBMS.
- Simplifies data handling by hiding the details of the relational model.
Example of an HQL query:
String hql = "FROM Employee E WHERE E.salary > :minSalary";
Query query = session.createQuery(hql);
query.setParameter("minSalary", 50000);
List<Employee> results = query.list();
Here, we select Employee objects with a salary greater than a specified value, using an object-oriented approach.