Advance-Java-Hibernate-1
Advance-Java-Hibernate-1
Cached
mohich
memoxy
red will be haldng Some data
perabita
'DATE
s) Exception Handlingi
Hibernade framenaoxk tself handles aall
checked exceptims but untime exeptiens
willhe thown
6)HQL Hibernate
There imight not
ury Longua
not beinbuttmethods for
all kind operakicns,using H I can
perfotm ny kihd of speratiths.
wibeQur Can
Jsing HQL
Hibernate..
Queries ce not speabic fo
Thele
datstabase,wken it Comes to Ho
any
queniei OUre database adependant
queries.
JPQL - Tava Persistance banguaqe
older nersiom wlhanede
Dewer versiox.
Howdoes Hibernate
Hibernate ioteracts ith databaie?
Persistance. xml
ul Hibernate
user Databawe
password
We have to t wrie Java
Hibernate program
Hibernate is not present
pre Jent in TDK
4o add we n
hibernate
In pom., Xm], we dapendany te Tava
Tara prot
wil ad dapendances
Dhibecnak.
repecdie databae drier
In Future, if wewp necd o interact with diferon
databasethen
database dzier
we we
change the especti
&o bae mulkiple
database oiers
Persistance.xml i Cconfiguroation file)
contain url, wer, password ot
database.
Hibecnafe will be fetching infoumaion.
databasefrom persistance xml
SuperModel O4
Rude I Reouen
Hibernate need to
instances of entity classes making clast
instantiate & manag
ures theO hibernatee
non- abstact ensues
public & in
Create stane ofcass
Rle M Rea.Son
Hibernake neade to cneak instances of entit
classes haring a public zeropara meBerised
constructor alosihernate tomake.
enitiesA oithout need of specific details.
Rale I
In Tava, priYate fetd wiually acceised
are
& moclified uting gekker and setter methed
Hibernate. need toUintecactwith attribus
enitiec. and publie
sekter mettods oloor
allawr beroate qetter
to do
this
Rule
affectiely
I Res son
Tmplemeating the Serializable Interface
iodicatesc inst ance Can be
Seriallzed comverbec t o byte shréam, und
sent acnesS netuwok.
netwok
Java DB
Appl
Server Servr
EnibyManager entityManagerkackony
ctibyManng
Eotiby Transaction
CadEnkhyMasager)
enityTran Sachion =
entitytlanaqer. get Transactiom);
Persistonce i
Persistonce isa heoer class present in
Javax. persistance.
- From tisctass. we wil be wsinq metha
cneateEnkihyManagertacboy (Shing persttaatuoit-ra
CrateEntibyManager
Tt is
Fackony 0
public stakic method wkich rehrn
entiby ManagerFocèarg
Laave multile
ave datahaethen you
E Create mulkiple
It Czoshucted entibyManagezhactiy
for specifc cataba
halps in establishi ng connect ion ith databse
Entibytaagee haco O of
qet sbiect
also Wked to înstontiak
entihyManaqer.
enkibgManager i lEME
EM-CRUD operaton
We
going ka create entityManaacr aiat
with ap
entitytanagerhcng
SntilyMamgpratany Persistance. createEntiby Maraqer
enfiyManagractn Fackeng'periciast ut.mae
5atihyMag
entayManager ntiMaragutackrg
Ceote EnhiSMana_er );
DATE
With hele
opecatins.
In entiby
entibyManagee, We Can perform CRUD
Like
persist ) entihyManager
merge
ger, we ave metheds
remoe c), find )
entibyransa cti¡n :
Intrface prsent in Tarax. persistance
an
package
with halp of entibytManager,we are going to
objeck for entiyTanzacten.
EMF
ET
EntibyTransaction enbtyManager.
entibyTrans action getTransachion();
EntibTransackion to club mltiple
operlkin
entity ransachion. begln C)j
insert record
-update recond ’Transaction
-clelete
ity Transactiom.commit )
Now call all stteme
transacons
'DATE'
persist ) :
void
persist (objeck Eaéiky
Make an instance managed persisent
ParameBes :
entiky - enkiby iaskane
Thsows :
Enkiby Exists Exception - Te the
erists. enihy aludy
TlegalArgumenk Excapian - If the
entiby
TransactionRequiredException - Ie hate i_na
transachËon when invokel
a container
C):
Throws
>zlegalArgumtnkExcaption
TransactionReguiredExcepbion
void remove
Parameteg:
entihy - enbly instance
Throwe:
TlagalArgumant Excepion
Transation Required Exeption
-iDATE
|HTbecnake
We
Mapping to build melationship
+What i relatfonship
Cannection betweentno more
han to
tabler.
2 2 2 2
beb
using Mapping
tuo
we
moe
an establish relationdip
thantwo tables.
In RDBMS,we to maintain elationship
betwcen tables
e(Primary iag ee
kable prima
wil be
other table )
$UniDiectionad Mapping i
student
id [PK] Attk Name
Keval 62134s2891
Cenkack rating-id
Alok 734 023124 1
2 2
3 2
student
Name CemtacE
2132|40S G
Keval
Alok 234 SG 78 90
3 Shubham 43214S6123
DATE
+Bi-Directional Mapping
id CekJ Name Contact ratinq i
Keva 2467809872
2
Alok |234S6 78)0
Shubham 2
376S3 10s244|
2 1 2
bank account
bank d accountg Add extra table ir
databaue
22
33
2
2 22
2 83
"DATE
t ManyTo One
Commentproduct_id
CPK1
Heading
Good Go for it
2 Bad' Wate
3 Wongt Don't Buy
Name Cost
mobile Go00
DnatotMany Mantou
'DATE
Takeaat fin
OneToMan VS
ManlaOne
DOneToMany
The sde Can acce99
teble
asso cited side entijes
mone flexible for updates.
To One"
Tue Side daesn't Lhave dinect
Cess to m side
So, iE is less exible
Student
namQ é-mai
lmobile-no.
Akoush AkQgng 82432)6S
2. yOacom 1234561
Yash Yacom
kalo:com 8|080 108
Kajo!
Subject
deserip tion trainer
Datetase
22 J2EE Middewr
33 webtech Fromtènd
Core-TavaGastcs Sk
student_subject
Stulid Sulb-id
(Relaionship)
1 22
2 22
0Student SubËect
Studentanhroller Subiect Contraller
plethads ) createStudent c CreakeSubËeckC)
i)
2) fetch
i)d )fetcA)
HRL}TeRL
Aind suaject a) update
Addne 4) feteh() 4)eMove
1)id Andl) ii) fetchAU
n
a Shuzants) Update r ) Subjec
Add subiect ) ist <Subject>
jnto ist
Student student
Sudet
S)
Subjeck add
stulent
sert stdtert f
Fnset bect
Insert Data
Ginoid
2. Pind Date
Update Paty Subjec to
H, Remoe Data eistina student
Suitch Cc
s witch ( )
Bi-di rection al
One ToOne
(@OneTo One
apping
CP) chasis
cost Mode' engineid ce Cario
350 2
2
CA4042000 2
Cwe3|3oooo THAR 3 3
DATE
Entit a¬ntihy
clas Car dass Engine
eiate int id: pivae int id
private hring model frvate
pringak
private OnToOne
OneToOne
privgte Eugine enginai Car car:
Ouetooe i bidirctanad
bidirrcttonal naapping eliminatizg
duplicake forcian-hog column
@Enti by
Car elais Eaginf
int id pxiate int id;
pzivate ti modul;
privae Engine
1Car
eginej private Cur car j
gttes setes
Car-jd Model e eid
CA