select clause in hibernate

select clause in hibernate

Example of select clause of hibernate?

View Answers

June 9, 2012 at 7:36 PM

Select clause is used for selection of records from a database. It picks up objects and properties and returns it in a query set.

Here is your query ?

SELECT emp.name, emp.salary, emp.dateOfJoin from Employee emp

This is your select clause, picking the employee details as employee name,salary and date of join from Employee table.

Example:

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;
import org.hibernate.criterion.Restrictions;

public class MainClass {
    public static void main(String[] args) {
        SessionFactory sessionFactory = HibernateUtil.getSessionFactory();
        Session session = sessionFactory.openSession();

        String hql="SELECT emp.name, emp.salary, emp.dateOfJoin from Employee emp";
        Query query=session.createQuery(hql);
        query.setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP);

        List objectList = query.list();
        Iterator iterator = objectList.iterator();
        System.out.println("Employee Name \t Salary \t Date of Join");
        while(iterator.hasNext()){          
            Map map = (Map)iterator.next();
            System.out.print(map.get("0"));
            System.out.print("\t\t"+map.get("1"));
            System.out.print("\t\t"+map.get("2"));
            System.out.println();
        }


        session.close();
    }
}

Output:

Hibernate: select employee0_.name as col_0_0_, employee0_.salary as col_1_0_, employee0_.date_of_join as col_2_0_ from employee employee0_
Employee Name    Salary      Date of Join
Mandy       20000       2010-03-12 00:00:00.0
Som     20000       1999-06-22 00:00:00.0
Mandy       15000       2003-12-23 00:00:00.0
Roxi        220000      2001-02-03 00:00:00.0

Ads









Related Tutorials/Questions & Answers:
Select Clause in hibernate.
Select Clause in hibernate.  Example of select clause of hibernate
Select Clause in hibernate.
Select Clause in hibernate.  Example of select clause of hibernate
Advertisements
Select Clause in hibernate.
Select Clause in hibernate.  Example of select clause of hibernate
select clause in hibernate
select clause in hibernate  Example of select clause of hibernate?   Select clause is used for selection of records from a database... This is your select clause, picking the employee details as employee name,salary and date
Hibernate SELECT Clause
Hibernate SELECT Clause In this tutorial you will learn how to use HQL select clause. Use of SELECT clause in hibernate is as same as it used in SQL... example which will demonstrate you how a HQL select clause can be used. To achieve
Hibernate In Clause
In this section we will introduce concept of Hibernate In Clause
where clause in select statement
where clause in select statement  In Mysql,I write the following query: select * from emp where designation = "MANAGER" But the actual value in the table is "manager" Will the above query retrieve any records? According to me
Hibernate Select Query
This tutorial contain the explanation of Select clause
select query using hibernate
select query using hibernate  Hi, can any one tell me to select records from table using hibernate. Thanks   Please visit the following link: Hibernate Tutorials The above link will provide you different
Hibernate ORDER BY Clause
Hibernate ORDER BY Clause In this tutorial you will learn about HQL ORDER BY clause. Purpose for using ORDER BY clause is similar to that it is used in SQL... by clause can be used. To achieve the solution of such problem at first I
Hibernate FROM Clause
Hibernate FROM Clause In this tutorial you will learn how to use HQL from clause. Use of FROM clause in hibernate is as same as it used in SQL... that is available to the other clause such as SELECT, DELETE. Example : Here I am giving
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. This clause is generally used with aggregate function and is used to return
SQL HAVING Clause
SQL HAVING Clause       Having clause is used with the select clause to specify a search condition for a group or aggregate. The HAVING clause works with where
HAVING Clause in JPQL (Java Persistence Query Language)
with the SELECT statement to filter the records. A HAVING clause restricts... to each group of grouped table, much as a WHERE clause is applied to a select list... system properly. Hibernate: select student0_.id as id0_, student0_.scourse
Hibernate WHERE Clause
Hibernate WHERE Clause In this tutorial you will learn how to use HQL where clause. Use of WHERE clause in hibernate is as same as it used in SQL... a HQL where clause can be used. To achieve the solution of such problem
Where Clause in SQL
Where Clause in SQL       The Where clause in SQL query is used  with the SELECT keyword... is The select query used with where clause, which search the data
Hibernate Group by Clause
In this tutorial we will discuss about Hibernate group by with example
SQL SELECT DISTINCT Statement
clause with the select statement. The SQL Distinct clause is used with the Select... SQL SELECT DISTINCT Syntax The SQL Distinct clause can be used... SQL SELECT DISTINCT Statement   
MySQL Nested Select Example
Clause. The Nested Select returns you the set of records from table based on the condition of nested select query specified in Where Clause. Understand... on the emp id specified in where clause. mysql> SELECT
Where clause
Where clause  I have doubt in Where clause .. i got a Employid from...; The WHERE clause is used to filter records.It is used to extract only those records that fulfill a specified criterion. SQL WHERE Syntax: SELECT column
Where clause with query in MySQL
is the various example of where clause: Suppose we have following table: mysql> select... (0.00 sec) Following shows more uses of where clause: mysql> select * from...Where clause with query in MySQL  Hi, I want to learn the where
select query
select query  how to write select query with where clause having multiple variables. example: i want to select the data from DB in which i want to check againest two variable in where cluase. String sql = "select * from
ModuleNotFoundError: No module named 'clause'
ModuleNotFoundError: No module named 'clause'  Hi, My Python... 'clause' How to remove the ModuleNotFoundError: No module named 'clause'... to install padas library. You can install clause python with following command
HQL Between clause, HQL Between example
HQL Between clause example In this tutorial you will learn how to use HQL Between clause to select a range of entity falling between 2 and 6. You can... and 6. The HQL Between used for this purpose is: // Create HQL Between clause
SQL HAVING Clause
SQL HAVING Clause       Having clause is used with the select clause to specify a search condition for a group or aggregate. The HAVING clause works with where
Hibernate Tutorials
Hibernate Query. In this example you will learn how to use the HQL from clause.   HQL Select Clause Example In this lesson we will write example code to select the data from Insurance table using Hibernate Select Clause
Mysql Date in where clause
Mysql Date in where clause     ... records from table employee1 on the basis of condition specified in WHERE clause... in Where clause. The given Query create table employee1 is used to create a table
Examples of Hibernate Criteria Query
clause, HQL Between example HQL Date Between Example HQL Sample SQL Select, HQL Select Example, HQL Select Query Hibernate Tutorials: Hibernate...Example code and running projects of Hibernate Criteria Query Here
php MySQL order by clause
php MySQL order by clause:       In SQL generally we use three clauses, select ,from, and where. .... Order by is one of the important clause of SQL. Order by clause is used to sort
Complete Hibernate 4.0 Tutorial
Language Hibernate select Clause Hibernate from Clause Hibernate where Clause Hibernate order by Clause Hibernate group by Clause
JDBC: WHERE Clause Example
JDBC: WHERE Clause Example In this section, we will discuss how to use WHERE Clause for putting condition in selection of table records using JDBC API. WHERE Clause : MySql Where Clause is used to write some condition and data

Ads