Example & Tutorial understanding programming in easy ways.

Which interfaces are defined to execute the query in the Hibernate?

Some interfaces are defined to execute the query in the Hibernate:


The following interfaces are defined to execute the query:


1. Query interface

2. Criteria interface


Both interfaces define several methods for controlling execution of a query.


To create a new Query instance, call either createQuery() or createSQLQuery(). 


The createQuery() method prepares an HQL query:


  Query q = session.createSQLQuery(

  "select {u.*} from USERS {u}", "u",

    User.class);


To obtain a Criteria instance, call createCriteria(), passing the class of the objects you want the quety to return. 


This is also called the root entity of the criteria query, the User in this example:


        Criteria c = session.createCriteria(User.class);

Read More →