Posts

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...

HQL Where Clause Example

Where Clause is used to limit the results returned from database. It can be used with aliases and if the aliases are not present in the Query, the properties can be referred by name. For example: from Insurance where lngInsuranceId='1' Where Clause can be used with or without Select Clause. Here the 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 Where Clause Example   * Where Clause With Select Clause Example   */ public class  WhereClauseExample {    public static void  main(String[] args) {    Session session =  null ;    try { ...

Hibernate Min() Function (Aggregate Functions)

In this section, we will show you, how to use the Min() function. Hibernate supports multiple aggregate functions. When they are used in HQL queries, they return an aggregate value ( such as   avg(...), sum(...), min(...), max(...) , count(*), count(...), count(distinct ...), count(all...)   ) calculated from property values of all objects satisfying other query criteria.  Following is a aggregate function (min() function) with their respective syntax. min(   [   distinct   |   all   ] object.property) The   Min()   function aggregates the minimum value of the given column.  Table Name: insurance ID insurance_name invested_amount investement_date 2 Life Insurance 25000 0000-00-00 00:00:00 1 Givan Dhara 20000  2007-07-30 17:29:05 3 Life Insurance   500 2005-10-15 00:00:00 ...