Magazine
 
Hibernate Query Language
 
insurance0_.invested_amount as
invested3_2_0_,
insurance0_.investement_date as
investem4_2_0_ from insurance insurance0_
where insurance0_.ID=?
First Name: Home Insurance
ID: 13
Hibernate: select insurance0_.ID as ID0_,
insurance0_.insurance_name as
insurance2_2_0_,
insurance0_.invested_amount as
invested3_2_0_,
insurance0_.investement_date as
investem4_2_0_ from insurance insurance0_
where insurance0_.ID=?
First Name: Motorcycle Insurance
ID: 14
Hibernate: select insurance0_.ID as ID0_,
insurance0_.insurance_name as
insurance2_2_0_,
insurance0_.invested_amount as
invested3_2_0_,
insurance0_.investement_date as
investem4_2_0_ from insurance insurance0_
where insurance0_.ID=?
First Name: Motorcycle Insurance

Here is the list of all HQL queries performed on the insurance table that you can use according to your requirement:

Clause
select

Query
“Select insurance.lngInsuranceId,
insurance.insuranceName,” +
“insurance.investementAmount,
insurance.investementDate from Insurance
insurance”;

Clause
where

Query
“Select insurance.lngInsuranceId,
insurance.insuranceName,” + “insurance.
investementAmount,
insurance.investementDate from Insurance
insurance “+ “ where
insurance.lngInsuranceId=’1'”;

 

Clause
order by

Query
“ from Insurance as insurance order by
insurance.insuranceName”;

Clause
group by

Query
“select sum(insurance.investementAmount),
insurance.insuranceName “ + “from Insurance
insurance group by
insurance.insuranceName”;

Hibernate Update Query

Insurance ins =
(Insurance)sess.get(Insurance.class, new
Long(1));
ins.setInsuranceName(“Travel Insurance
“);
ins.setInvestementAmount(20000);
ins.setInvestementDate(new Date());
sess.update(ins);
tr.commit();

Hibernate Delete Query

String hql = “delete from Insurance insurance
where id = 2”;
Query query = sess.createQuery(hql);
int row = query.executeUpdate();

Example list of Aggregate functions:

Funtion Query
Avg() “select avg(investementAmount)
from Insurance insurance”
Max() select max
(investementAmount)
fromInsurance insurance”
Min() “select min(investementAmount)
from Insurance insurance”

 

Feb 2008 | Java Jazz Up |35
 
previous
index
next
 
View All Topics
All Pages of this Issue
Pages: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,

30
, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53 , 54, 55, 56, 57,

58
, 59, 60, 61, 62, 63 , 64, 65 , 66 , 67 , 68 , 69 , 70 , 71 , 72 ,

Download PDF