From the course: Java Persistence with JPA and Hibernate

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

Criteria queries

Criteria queries

- [Instructor] JPQL queries, named queries, and native queries are different ways in which you can query the database when using an ORM framework, like Hibernate. Criteria queries are yet another way of querying. These are sometimes known as dynamic queries. When you have a lot of filter criteria in your query, for instance, if you are writing some search logic in your application, you wouldn't exactly know what parameters you'll need to pass your query. In this kind of a situation, you cannot use JPQL queries, but criteria queries are there for your rescue. So criteria queries are specifically helpful if you don't know in advance what filter criteria you have in your query. The criteria API allows to build up a query programmatically where different filter rules and logical conditions can be applied to it. Let's check out a simple example first. Before you begin, you should run the mariadb-init.sql script and mariadb-07_07.sql script. In the Main class, criteriaQueries method, you…

Contents