Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Hibernate HQL group By.
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ratna rathor
HQL group By.
1 Answer(s)      2 years and 7 months ago
Posted in : Hibernate


How to use group by in HQL?


Advertisement
View Answers

May 31, 2012 at 6:55 PM


In general group by clause is used with aggregate functions for grouping the result. It is also a powerful option of sorting as it returns the list grouping in ascending order. It allows the Hibernate to fetch information from the database and group by them under the specified attribute.

package net.roseindia.main;

import java.util.*;
import net.roseindia.table.Employee;
import net.roseindia.util.HibernateUtil;
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class HQLGroupBy{
    public static void main(String []args){
        SessionFactory sessionFactory =HibernateUtil.getSessionFactory();
        Session session=sessionFactory.openSession();
        String hql="Select emp.name FROM Employee emp GROUP BY name";
        Query query=session.createQuery(hql);
        query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);
        List objectList = query.list();
        Iterator iterator = objectList.iterator();
        while(iterator.hasNext()){          
            Map map = (Map)iterator.next();
            System.out.println(map.get("0"));
            }
        session.close();
    }
}

Output :

Hibernate: select employee0_.name as col_0_0_ from employee employee0_ group by employee0_.name
Mandy
Ron
Roxi
Som


Related Tutorials/Questions & Answers:
HQL group By.
HQL group By.  How to use group by in HQL?   In general group by clause is used with aggregate functions for grouping the result...=sessionFactory.openSession(); String hql="Select emp.name FROM Employee emp GROUP BY name
HQL Group By Clause Example
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
Advertisements
HQL
HQL  What is the HQL in hibernate ? Explain the use of HQL.   Hi Friend, Please visit on this link....... Hibernate Query Language
Hibernate GROUP BY Clause
Hibernate GROUP BY Clause In this tutorial you will learn how to use HQL GROUP BY clause. GROUP BY clause in HQL is used as same as it is used in SQL... a simple example which will demonstrate you how a HQL group by clause can
HQL order by.
HQL order by.  HQL Order by query giving problem.   Order by clause is one way to group a series of object in sorted form. There is two... into descending order you can follow the following HQL ? String hql="Select emp FROM
HQL query
HQL query  how to select only password based on username using HQL query from login table where uname and paswrd are two column names
group by sorting
group by sorting  group by sorting of data in SQL
HQL Query
HQL Query  Hibernate query language: How to use a left join in Hibernate query language. Can somebody help with an example. I am getting a unexpected token error in HQL Query tool If I use joins
HQL in hibernate ? Explain the use of HQL.
HQL in hibernate ? Explain the use of HQL.  What is the HQL in hibernate ? Explain the use of HQL.   HQL stands for Hibernate Query...(); Session session = sessionFactory.openSession(); String hql="SELECT
HQL Sample
HQL Sample In this site there are many tutorials and example of HQL. These examples comes with HQL sample code that you can download and run on your computer and learn the HQL by modifying and executing these examples. The HQL Sample
convert into hql
convert into hql   String sqlListSurveys= "select distinct s.surveyAutoID, s.surveyTitle, date(s.modifiedOn) modifiedOn, s.createdOn, " + "( CASE s.surveyState WHEN '0' THEN 'Created' WHEN '1' THEN 'Published
how to convert sql into hql
how to convert sql into hql   StringBuffer questionDataSql = new... distinct q.questionVerbiage, qt.questionType, ") .append("GROUP...,'') branchingLogic ") .append("FROM question q left join
Hibernate Query Language (HQL)
Hibernate Query Language (HQL)  What is Hibernate Query Language (HQL)?   HQL is much like SQL and are case-insensitive, except... and execute it against underlying database if HQL is used in the application. HQL
Hibernate HQL Update
In this section we will discuss HQL update with example
Hibernate delete HQL - Hibernate
Hibernate delete HQL  Hi I am trying hibernate tutorial. But delete HQL tutorial not working properly. It gives null pointer exception. Query class has method executeUpate() & not executeUpdate
What is Hibernate Query Language (HQL)?
What is Hibernate Query Language (HQL)?  Hi, What is Hibernate Query Language (HQL)? thanks
Using Min, Max and Count on HQL.
Using Min, Max and Count on HQL.  How to use Min, Max and Count on HQL
Hibernate-HQL subquery - Hibernate
Hibernate-HQL subquery  Hi, I need to fetch latest 5 records from a table.My query goes here. select * from (select * from STATUS... in HQL which should return list of "Status" type beans.Is it possible?If yes
HQL update problem
HQL update problem  public void saveGuest(List<Long> listid) throws HibernateException{ SessionFactory sf... table HQL plz help
Delete HQL query - Hibernate
Delete HQL query  Hi I am trying hibernate tutorial. But delete HQL tutorial not working properly. It gives null pointer exception. Query class has method executeUpate() & not executeUpdate(); log4j:WARN No appenders
Update a group of records with one value in the same group
Update a group of records with one value in the same group  I want to update my table group wise, i have three cases AA,BB,CC , if group of records... be update with AA. If group is not having AA value second priority is BB next CC
Count distinct value in HQL.
Count distinct value in HQL.  How do you count distinct value in HQL?   count(distinct fieldName) returns number of distinct value of the table under specified field name. Example : package net.roseindia.main
Delete Query using HQL
Delete Query using HQL  Can we write 'AND' with 'WHERE' clause in delete query using HQL? For example: delete from table name where field1 = value1 and field2 = value2   The example query i have written
HQL Between clause, HQL Between example
HQL Between clause example In this tutorial you will learn how to use HQL... and 6. The HQL Between used for this purpose is: // Create HQL Between clause String HQL_QUERY = "select c from Customer c where c.id between 2 and 6"
SQLl query count and group by
SQLl query count and group by  How to write a sql query to count and group by the data?   Sql query to count the data and group the data using group by function... Select Name, Count(Name) As Count From Table Group
GROUP BY IN NESTED QUERY
GROUP BY IN NESTED QUERY  Hello Every One, Query to use GROUP BY CLAUSE IN NESTED QUERY SELECT STATEMENT in mysql database.If u know please help me.thanks
HQL, Hibernate Query Language
HQL - Hibernate Query Language In this tutorial on HQL we will learn how to use HQL to perform CRUD operations on the persistence Entity objects. This is complete tutorial on HQL. You will find almost all the topics related to HQL
xcode group folder
xcode group folder  I wanted to show all files in xcode in a group format.. left and right Group & Files. earlier it was showing in groups... the steps.. View -> Smart Groups -> All Files it'll group all the files
HQL Statement: Please help me
HQL Statement: Please help me  Select ProductFamily.* from ProductFamily, ProductGroup, Product where ProductFamily.productFamilyVersionId... = Product.productGroupVersionId and Product.lobId = ? Can you please help me equallent HQL
Mysql Group By
Mysql Group By       Mysql Group By statement is conjecture term used with the aggregate functions to group the result-set by specified one or more columns. Understand
Mysql Group By
Mysql Group By       Mysql Group By statement is conjecture term used with the aggregate functions to group the result-set by specified one or more columns. Understand with Example
Advertisements
 

 

 

DMCA.com