Anda di halaman 1dari 16

Apex T. G. India Pvt.

Ltd
Hibernate Query
Language
1
HQL

Hibernate Framework comes with a powerf!


ob"ect#oriented $er% !an&a&e 'Hibernate Qer%
Lan&a&e)HQL*.

It+s ver% simi!ar to ,QL except that we se -b"ects


instead of tab!e names. that makes it more c!ose
to ob"ect oriented pro&rammin&.

Hibernate $er% !an&a&e is case#insensitive


except for "ava c!ass and variab!e names.
1
HQL

Hibernate Qer% Lan&a&e is sed to execte


$eries a&ainst database.

Hibernate atomatica!!% &enerates the s$! $er%


and execte it a&ainst nder!%in& database if HQL
is sed in the app!ication.

HQL is based on the re!ationa! ob"ect mode!s and


makes the ,QL ob"ect oriented.
1
HQL

Hibernate Qer% Lan&a&e is extreme!% powerf!


and it spports Po!%morphism. Associations. /ch
!ess verbose than ,QL.

0eason To se1

F!! spport for re!ationa! operations1 HQL a!!ows


representin& ,QL $eries in the form of ob"ects.
Hibernate Qer% Lan&a&e ses 2!asses and
properties instead of tab!es and co!mns.
1
HQL

0etrn res!t as -b"ect1 The HQL $eries retrn the


$er% res!t)s* in the form of ob"ect)s*. which is
eas% to se. This e!iminates the need of creatin&
the ob"ect and pop!ate the data from res!t set.

Po!%morphic Qeries1 HQL f!!% spports


po!%morphic $eries. Po!%morphic $eries res!ts
the $er% res!ts a!on& with a!! the chi!d ob"ects if
an%.


1
HQL

3as% to Learn1 Hibernate Qeries are eas% to !earn


and it can be easi!% imp!emented in the
app!ications.

,pport for Advance featres1 HQL contains man%


advance featres sch as pa&ination. fetch "oin
with d%namic pro4!in&. Inner5oter5f!! "oins.
2artesian prodcts. It a!so spports Pro"ection.
A&&re&ation )max. av&* and &ropin&. -rderin&.
,b $eries and ,QL fnction ca!!s.
1
HQL

6atabase independent1 Qeries written in HQL are


database independent )If database spports the
nder!%in& featre*.

7nderstandin& HQL ,%ntax

Hibernate Qer% Lan&a&e ma% consist of


fo!!owin& e!ements1

2!ases

A&&re&ate fnctions
1
HQL

,b $eries
2!ases in HQL1

from

se!ect

where

order b%

&rop b%
1
HQL
A&&re&ate fnctions are1

av&)...*. sm)...*. min)...*. max)...*

cont)8*

cont)...*. cont)distinct ...*. cont)a!!...*


1
HQL 2!ase
From 2!ase1

It is same as se!ect c!ase in ,QL.+from


3mp!o%ee+is same as+se!ect 8 from 3mp!o%ee+. 9e
can a!so create a!ias sch asfrom 3mp!o%ee
emporfrom 3mp!o%ee as emp.For 3xamp!e1
session.createQer%):from
3mp!o%ee:*;
1
HQL
<oin 2!ase1

HQL spports inner "oin. !eft oter "oin. ri&ht oter


"oin and f!! "oin. For 3xamp!e1

In this $er%. 3mp!o%ee c!ass sho!d have a


variab!e named address.
se!ect e.name. a.cit% from 3mp!o%ee e I==30 <-I=
e.address a
1
HQL
A&&re&ate Fnctions1

HQL spports common!% sed a&&re&ate fnctions


sch as cont)8*. cont)distinct x*. min)*. max)*.
av&)* and sm)* etc .For 3xamp!e1
session.createQer%):se!ect sm)sa!* from ,tdent:*;
1
HQL
3xpressions1

HQL spports arithmetic expressions )>. #. 8. 5*.


binar% comparison operators )?. @?. A?. A@. B?.
!ike*. !o&ica! operations )and. or. not* etc. . For
3xamp!e1 session.createQer%):se!ect sa! from ,tdent where
id?1:*;
1
HQL

HQL a!so spports order b% and &rop b% c!ases.

HQL a!so spports sb#$eries "st !ike ,QL


$eries.

HQL spports 66L. 6/L and exectin& store


procedres too.
1
2ontact s
Thanks
facebook.com/apex.tgi
twitter.com/ApextgiNoida
pinterest.com/apextgi
Stay Connected with us for more chapters on JAVA

Anda mungkin juga menyukai