Junior — Middle
Can you explain what Hibernate Query Language (HQL) is and what it is used for?
sobes.tech AI
Answer from AI
Hibernate Query Language (HQL) is an object-oriented query language used in Hibernate for working with databases. It is similar to SQL but operates on classes and their properties rather than tables and columns. HQL allows writing queries that Hibernate translates into SQL, taking into account the specifics of the database management system used.
The main purpose of HQL is to simplify data handling by abstracting the developer from the specific database structure and SQL syntax. This facilitates code portability and object-relational mapping.
Example of a simple HQL query:
String hql = "FROM User WHERE age > 18";
List<User> adults = session.createQuery(hql, User.class).list();
Here, we select all User objects where the age is greater than 18.