Example & Tutorial understanding programming in easy ways.

What is Hibernate QBC (Query By Criteria)?

QBC (Query By Criteria): Hibernate provides the some different way to manipulating object and in turn data available in RDBMS tables. One of the methods is the Criteria API which allwos you to build up a criteria query object programmatically where you can apply filtration rules and logical condition.


In the Hibernate, Hibernate Session interface provides createCriteria() method which can be used to create a Criteria object that returns instances of the persistence object's class when your application executes a criteraia query.


We have an simple example of a criteria query is one which will simply return every object that corresponds to the Employee class.


Criteria cr = session.createCriteria(Employee.class);

List results = cr.list();


Restrictions with Criteria:


We can use add() method available for Criteria object to add restriction for a criteria query. Following is the example to add a restriction to return the records with salary is equal to 12000:


Criteria cr = session.createCriteria(Employee.class);

cr.add(Restrictions.eq("salary", 12000));

List results = cr.list();

Read More →
Search
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!