criteria in hibernate

Q. What is criteria in hibernate? Write an example of criteria using annotation?

Steps to run below example –

Step 1 – Create a java project(Since we are not using maven for jar/library, need to download the jar and add manually in the project)

Step 2 – Download hibernate jar and add it to project( right-click on project/properties/java build path/libraries/add external jars/ browse and add).

Step 3 – define the below classes and run the main class(Don’t forget to change the username and password in hibernate.cfg.xml for the database, that you have given during installation of Oracle in your machine ).

 

Let’s see simple example for criteria –

Book.java – 

hibernate.cfg.xml –

CriteriaQueryExample.java – 

When you run this program expected output is – 

Top