You are on page 1of 9

decompiler : is used to convert a .class file into a .java file if u want to see the source code of any .

class file topics for today ============== how to map java level inheritance to the table level how to map one to many relationship betwen classes to the table level how to map many to many relationship between classes to the table level understand fetch strategies eager fetch

lazy fetch

Loan int loanId; int loanAmount int num f!rs; float roi; "ehicleLoan $tring vehicle%ype $tring model; float vehicle'ost; (ayment int paymentId; float amount; 'he)ue(ayment int che)ue&umber; 'ard(ayment $tring card%ype; #omeLoan $tring builder&ame; $tring propertyLocation

$tring ban*&ame

long card&umber

+ choices ,strategies - for table creation .. single table containing columns corresponding to all the member variables of parent and child class
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)

/. + different tables
@Inheritance(strategy=InheritanceType.TABLE_PER_CLASS)

child tables contain columns of parent class as well as its own member variables +. + different tables
@Inheritance(strategy=InheritanceType.J INE!)

child table contains columns of its own class and one more column paymentid which will be pointing to the parent table0s primary *ey the strategy is specified at base table level0 '12A%2 %A3L2 4payment4 , 4paymentId4 int,..- & % &5LL6 4customer&ame4 varchar,/77- 829A5L% &5LL6 4paymentAmount4 float & % &5LL6 (1I:A1! ;2! ,4paymentId4-

'12A%2 %A3L2 4cardpayment4 , 4card&umber4 bigint,/<- & % &5LL6 4card%ype4 varchar,/77- 829A5L% &5LL6 4e=piry8ate4 datetime 829A5L% &5LL6 4paymentId4 int,..- & % &5LL6 (1I:A1! ;2! ,4paymentId4-6

;2! 49;7>?/>@3>9<A''@+A4 ,4paymentId4-6 ' &$%1AI&% 49;7>?/>@3>9<A''@+A4 9 12IB& ;2! ,4paymentId4- 129212&'2$ 4payment4 ,4paymentId4inserting a child record also inserted a parent record Cid is re)uired only at base class level to fetch a record based on primary *ey
sessi"n.get # #(Pay$ent.c%ass&'())* # # '()#is#the#pri$ary#+ey#,a%-e# t"#.etch#rec"r/s#0ase/#"n#"ther##c"n/iti"n -se#either#s1%#"r#h1%#1-ery s1%#2"r+s#2ith#ta0%e#an/#c"%-$n#na$es h1%#2"r+s#2ith#c%ass#an/#$e$0er#,aria0%e#na$es

-p/ate sessi"n.$erge(cp')* t3.c"$$it()*44#hi0#generates#-p/ate#state$ent

sessi"n./e%ete(cp')* 44a0",e#generates#/e%ete#state$ent
t3.c"$$it()*

sessi"n./e%ete $apping#"ne#t"#$any#re%ati"nship Acc"-nt int#acc"-ntI/* String#acc"-ntType* /"-0%e#0a%ance*

Transacti"n int#transacti"nI/* String#transacti"nType* /"-0%e#transacti"nA$"-nt*

Categ"ry int#categ"ryI/* String#categ"ryNa$e*

Pr"/-ct# int#pr"/-ctI/* String#pr"/-ctNa$e* .%"at#-nitPrice "ne#acc"-nt#can#ha,e#$any#transacti"ns#ass"ciate/#2ith#it "ne#categ"ry#can#ha,e#$any#pr"/-cts#in#it .r"$#the#acc"-nt4categ"ry#p"int#".#,ie2&#it#is#a#"ne#t"#$any#re%ati"n#

.r"$#the#pr"/-ct4transacti"n#p"int#".#,ie2&#"ne#rec"r/#in#this#ta0%e# 2i%%#p"int#t"#"ne#rec"r/#in#the#parent#ta0%e $any#pr"/-cts4transacti"ns#in#"ne#categ"ry4acc"-nt#ta0%e

parent#c%ass c%ass#Acc"-nt List5Transacti"n6#t%ist*

%ist#7#e%e$ents#are#"r/ere/&#/-p%icates#are#"+ set#7#n"#"r/er&#n"#/-p%icates $ap#7#+ey#,a%-e#pair&#+ey#sh"-%/#0e#-ni1-e

TreeSet&#S"rte/TreeSet $aintains#e%e$ents#in#"r/ere/#.ashi"n the#nat-ra%#"r/ering#".#the#e%e$ents#is#-se/ a%pha0etica%#"r/er#."r#strings n-$erica%#"r/er#."r#n-$0ers any#"ther#"r/er#can#0e#speci.ie/#-sing#the#c"$parat"r#an/#c"$para0%e# itner.aces#

generate#getters#an/#setters#."r#a0",e 8-st#a0",e#getter#$eth"/ 2rite#this#ann"tati"n# @ neT"9any

hi0ernat#2i%%#create#t2"#ta0%es "ne#."r#the#parent#c%ass#ha,ing#c"%-$ns#sa$e#as#$e$0er#,aria0%es "ne#."r#the#chi%/#c%ass#ha,ing#its#"2n#c"%-$ns#p%-s#"ne#e3tra#c"%-$n# re.erring#t"#the##parent#ta0%e#pri$ary#+ey#c"%-$n "ne#trainer#$any#st-/ents "ne#st-/ent#can#%earn#.r"$#$any#trainers#a%s"

in#case#".#re%ati"nship#0et2een#ta0%es&#re$e$0er#t"#gi,e#the#i/# ann"tati"n#at#$eth"/#%e,e%#n"t#at#$e$0er#,ari0a%e#%e,e%

@ neT"9any @J"inC"%-$n(na$e=:ne2c"%-$n:) p-0%ic#List5Pr"/-ct6#getPr"/List()#; ret-rn#pr"/List* <

,#r#persisting#categ"ry#"n%y#an/#n"t#pr"/-ct hence#err"r#at#r-nti$e ,#2ant#pr"/-ct#rec"r/s#t"#0e#inserte/#2hen#,#insert# categ"ry# hence#-s#ethe#."%%"2ing

@ neT"9any(casca/e=Casca/eType.ALL)
i/enti.y#the#appr"priate#$e$0er#,aria0%e#."r#the#re%ati"n#an/#-se#the#appr"priate# ann"tati"n# a%2ays#gi,e#annt"ati"ns#a%"ng#2ith#getter#$eth"/

try#"-t -p/ating#parent&#-/pates#chi%/#rec"r/s

/e%eting#parent&#/e%e%es#chi%/#rec"rs# sesi"n.get(Categ"ry&'') sesi"n./e%ete()

CREATE#TABLE#=(n/0atchpr"/-ct=#( ##=pr"/-ctI/=#int('')#N T#N>LL& ##=pr"/-ctNa$e=#,archar((??)#!E@A>LT#N>LL& ##=-nitPrice=#.%"at#N T#N>LL& ##=ne2c"%-$n=#int('')#!E@A>LT#N>LL& ##PRI9ARA#BEA#(=pr"/-ctI/=)& ##BEA#=@BCAC?(!!!DCEC?EA(=#(=ne2c"%-$n=)&

##C NSTRAINT#=@BCAC?(!!!DCEC?EA(=#@ REIGN#BEA#(=ne2c"%-$n=)#RE@ERENCES# =(n/0atchcateg"ry=#(=categ"ryI/=) )# $any#t"#$any "ne#pr"/-ct#can#ha,e#$any#ingre/ients "ne#ingre/ient#can#0e#-se/#in#$any#pr"/-cts "ne#pers"n#can#h"%/#$any#acc"-nts "ne#acc"-nt#can#ha,e#8"int#"2ners "ne#trainer#$any#st-/ents "ne#st-/ent#can#%earn#.r"$#$any#traines

in a many to many relation6 a new mapping table is created containing two columns trainer table t<<. t<</ student table s<<. s<</ mapping table name can be controlled trainerid t<<. t<<. t<</
@9anyT"9any @J"inTa0%e(na$e=:st-/ent_trainer:& 8"inC"%-$ns=@J"inC"%-$n(na$e=:traineri/:)& in,erseJ"inC"%-$ns=@J"inC"%-$n (na$e=:st-/enti/:))

*avita ajit

divya shivani

studentid s<<. s<</ s<<.

8"inc"%-$n#is#the#c"%-$n#".#the#ta0%e#2here#-#ha,e#2ritten#this#ann"tati"n

in,erse8"inc"%-$n#is#the#c"%-$n#".#the#"ther#ta0%e#in,"%,e/#in#the#re%ati"n#

.etch=@etchType.LAFA

i.#a#parent#rec"r/#is#.etche/&#sh"-%/#the#re%ate/#chi%/#rec"r/s#a%s"#0e#.etche/ i.#.etch#is#eager&#a0",e#2i%%#ta+e#p%ace i.#.etch#is#set#t"#%aGy&#"n%y#parent#rec"r/#is#retrie,e/.#chi%/#rec"r/s#2i%%#0e# .etche/#"n%y#2hen#a#separate#ca%%#t"#the#chi%/#c%ass#is#$a/e#i.e# getTransacti"ns#"r#getPr"/-cts#$eth"/#is#ca%%e/# 0i/irecti"na%#%""+-p# i.#an#acc"-nt#i/#is#+n"2n&#can#i#+n"2#the#transacti"ns#ass"ciate/#2ith#it i.#a#transacti"n#is#+n"2n&#can#i#.in/#the#acc"-nt#".#this#transacti"n

i.#-r#re1-ire$ent#is#"n%y#-ni/irecti"na% re$",e#a%%#ann"tatins#in#the#sec"n/#c%ass#an/#test#y"-r#c"/e it#2i%%#sti%%#2"r+#0-t#the#re,erse#%""+-p#2i%%#nt"#0e#p"ssi0%e

we have persisted account record 6 related transactions also got persisted try persisting transaction related account records should also get done inheritance one to many many to many fetch type eager and lazy cascade insertD deleted parent child not deleted dependent column replaced with null merge delete on mon

select )ueries h)l criteria restriction caching

You might also like