From the course: Java Database Access with Hibernate

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Criteria query API

Criteria query API - Java Tutorial

From the course: Java Database Access with Hibernate

Start my 1-month free trial

Criteria query API

- [Instructor] Next, let's take a look at the create criteria API. The Hibernate session interface contains several create criteria methods. We can use this create criteria to allow us to restrict the results that we get back from our query. Let's give it a try. On line 48, I'm going to create a criteria object called criteria, and that's going to be equal to session.createCriteria. When using the session.createCriteria, we pass a object's class, or its entity name, to the method. So, in this case, I want to use the employee class. Next, I want to identify that I want to create a list of results, so let's do list employees = criteria.list Now, if I run the program, it will query the employee table and list out all the employees. So, we can see there's Peggy Fisher, Cy Smith, Stephanie Zook, Shawna Boreman, et cetera. Alright, that seems to be working. There's a couple other things we can do with the create criteria method. One is, we can actually restrict the results using…

Contents