Select Clause in hibernate.

Select Clause in hibernate.

Example of select clause of hibernate ?

View Answers

June 9, 2012 at 7:32 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
Ron        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









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 lesson we will write example code to select the data from Insurance table using Hibernate Select Clause. The select clause picks up
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... a simple example which will demonstrate you how a HQL select clause can
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 In Clause
In this section we will introduce concept of Hibernate In Clause
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... how a HQL order by clause can be used. To achieve the solution
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 :ADS_TO_REPLACE_1 Here
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...:WARN Please initialize the log4j system properly. Hibernate: select
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... will demonstrate you how a HQL where clause can be used. To achieve the solution
Where Clause in SQL
Where Clause in SQL       The Where clause in SQL query is used  with the SELECT keyword... of the above query is The select query used with where clause, which search
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... DISTINCT Syntax The SQL Distinct clause can be used with the Select... SQL SELECT DISTINCT Statement   
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?
What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?  What is the difference between a HAVING CLAUSE and a WHERE CLAUSE?   Hi, Both HAVING and WHERE clause used for specifying the search condition in SQL
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 and Having clause
Where and Having clause   hii, What is the difference between where and having clause?   hello,ADS_TO_REPLACE_1 WHERE clause is used to impose condition on SELECT statement as well as single row function and is used
MySQL Select Statement
clause. The SELECT statement is used to retrieve the records from the table...; SELECT Name FROM Emp ORDER BY Name; The LIMIT Clause The LIMIT clause can... MySQL Select Statement     
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
HQL from clause Example
clause. The from clause is the simplest possible Hibernate Query. Example of from... Hibernate: select insurance0_.ID as col_0_0_ from insurance insurance0_ ID: 1 Hibernate: select insurance0_.ID as ID0_, insurance0
HQL Where Clause Example
lngInsuranceId='1'ADS_TO_REPLACE_1 Where Clause can be used with or without Select... LanguageADS_TO_REPLACE_2 Hibernate: select insurance0_.ID as col_0_0_ from... Hibernate: select insurance0_.ID as ID0_, insurance0_.insurance_name
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 Group By Clause Example
Hibernate: select sum(insurance0_.invested_amount... HQL Group By Clause Example       Group by clause is used to return the aggregate values
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
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
WHERE Statement in SQL
WHERE Clause in SQL        WHERE clause is used with the SELECT keyword. ' Where' is a clause which is used for searching the data with a particular condition.  
Mysql Date in where clause
Mysql Date in where clause     ... records from table employee1 on the basis of condition specified in WHERE clause... Mysql data in Where clause. The given Query create table employee1 is used
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
hibernate - Hibernate
(); session =sessionFactory.openSession(); //Create Select Clause HQL String SQL_QUERY ="Select Branches.branch_id from Branches branches"; Query query... Hibernate; import org.hibernate.Session; import org.hibernate.*; import
Hibernate Tutorials
Hibernate Select Clause.   HQL Where Clause Example Where... to use the HQL from clause.   HQL Select Clause Example... Hibernate Tutorials       Deepak Kumar Deepak
JDBC: WHERE Clause Example
(); // Selecting records under Where Clause condition String sql = "SELECT...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
JPA Query with where clause and group by function
JPA Query with where clause and group by function  Any thing wrong in my JPA Query. TypedQuery<RaBdrRating> uQuery = (TypedQuery<RaBdrRating>) entityManager.createQuery("SELECT activePackage,SUM(duration),SUM
JDBC: LIKE Clause Example
JDBC: LIKE Clause Example In this section, you will learn how to use LIKE Clause for selection of table records using JDBC API. LIKE Clause : Like Clause is used for comparing part of string. For pattern matching we use
Explain the use of the ‘LIKE’ keyword used in the WHERE clause?
Explain the use of the ?LIKE? keyword used in the WHERE clause?   Explain the use of the ?LIKE? keyword used in the WHERE clause
Explain the use of the ‘LIKE’ keyword used in the WHERE clause?
Explain the use of the ?LIKE? keyword used in the WHERE clause?   Explain the use of the ?LIKE? keyword used in the WHERE clause
SQL Aggregate Functions Where Clause
SQL Aggregate Functions Where Clause       SQL Aggregate Functions Where Clause return you the aggregate sum of the records based on the condition specified in Where Clause condition
SQL Select, HQL Select Example, HQL Select Query
*/ Transaction tx = session.beginTransaction(); // Create Select Clause HQL String... is the output of the example when executed: Hibernate: select customer0_.id as id0...HQL Select In this tutorial we will learn how to use HQL Select statement
SET and SELECT
SET and SELECT  hello, What is difference between SET & SELECT in sql????   hii,ADS_TO_REPLACE_1 SET : The set statement is used to the update query. SELECT : The select statement is used to display the all
Using WHERE Clause in JDBC
to the SELECT statement. The WHERE clause searches the specific results by the SELECT statement. Example of WHERE Clause SELECT Name from... Using WHERE Clause in JDBC    Where
select query
select query  how to retrieve a single image from mysql table using $row[] value
how to use comma separated value list in the where clause oracle
how to use comma separated value list in the where clause oracle  Hi, how to use comma separated value list in the where clause oracle Thanks   HI, Following code will help you: select * from employee where id
hibernate - Hibernate
hibernate  is there any tutorial using hibernate and netbeans to do a web application add,update,delete,select   Hi friend, For hibernate tutorial visit to : http://www.roseindia.net/hibernate/index.shtml
hibernate - Hibernate
(); //Create Select Clause HQL String SQL_QUERY ="Select... Hibernate; import org.hibernate.Session; import org.hibernate.*; import...   Hi Radhika, i think, you hibernate configuration

Ads