Posts

Showing posts with the label Hibernate

Hibernate Criteria Query Example

The Criteria interface allows to create and execute object-oriented queries. It is powerful alternative to the HQL but has own limitations. Criteria Query is used mostly in case of multi criteria search screens, where HQL is not very effective.  The interface org.hibernate.Criteria is used to create the criterion for the search. The org.hibernate.Criteria interface represents a query against a persistent class. The Session is a factory for Criteria instances. Here is a simple example of Hibernate Criterial Query:   package  roseindia.tutorial.hibernate; import  org.hibernate.Session; import  org.hibernate.*; import  org.hibernate.cfg.*; import  java.util.*; /**   *  @author  Deepak Kumar   *    * http://www.roseindia.net  Hibernate Criteria Query Example   *     */ public class  HibernateCriteriaQueryExample...

HQL Order By Example

Order by clause is used to retrieve the data from database in the sorted order by any property of returned class or components. HQL supports Order By Clause. In our example we will retrieve the data sorted on the insurance type. Here is the java example code:   package  roseindia.tutorial.hibernate; import  org.hibernate.Session; import  org.hibernate.*; import  org.hibernate.cfg.*; import  java.util.*; /**   *  @author  Deepak Kumar   *    * http://www.roseindia.net HQL Order by Clause Example   *     */ public class  HQLOrderByExample {    public static void  main(String[] args) {    Session session =  null ;    try  {    // This step will read hibernate. cfg.xml and prepare...

HQL Group By Clause Example

Group by clause is used to return the aggregate values by grouping on returned component. HQL supports Group By Clause. In our example we will calculate the sum of invested amount in each insurance type. Here is the java code for calculating the invested amount insurance wise: package  roseindia.tutorial.hibernate; import  org.hibernate.Session; import  org.hibernate.*; import  org.hibernate.cfg.*; import  java.util.*; /**   *  @author  Deepak Kumar   *    * http://www.roseindia.net  HQL Group by Clause Example   *     */ public class  HQLGroupByExample {    public static void  main(String[] args) {    Session session =  null ;    try  {    // This step will read  hibernate.cfg.xml and...