hibernate hql in
时间: 2023-07-12 17:08:50 浏览: 125
Hibernate HQL (Hibernate Query Language) is an object-oriented query language used to retrieve data from a database using Hibernate, a popular Object-Relational Mapping (ORM) framework for Java.
HQL syntax is similar to SQL, but instead of operating on tables and columns, HQL operates on persistent classes and their properties. Here is an example of a basic HQL query:
```
String hql = "FROM Customer c WHERE c.age > 18";
Query query = session.createQuery(hql);
List<Customer> customers = query.list();
```
In this example, we are querying the `Customer` table where the age of the customer is greater than 18. We then create a `Query` object by passing the HQL string to the `createQuery` method of the `Session` object. Finally, we call the `list` method on the `Query` object to retrieve a list of `Customer` objects that match the query.
HQL also supports advanced features such as joins, subqueries, and aggregate functions, allowing for more complex queries.
阅读全文