Hibernate needs to know how to load and store objects of the persistent class. This is where the mapping file comes into play. The mapping file tells the database what table in the database it has to access, and what columns in that table it should use.
Hibernate needs to know how to load and store objects of the persistent class. This is where the mapping file comes into play. The mapping file tells the database what table in the database it has to access, and what columns in that table it should use.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online from Scribd
Hibernate needs to know how to load and store objects of the persistent class. This is where the mapping file comes into play. The mapping file tells the database what table in the database it has to access, and what columns in that table it should use.
Copyright:
Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online from Scribd
O What are the common tiers in an N-Tier application?
Answer: Presentation - responsible for displaying data only
Service responsible for business logic. Persistence responsible for storing/retrieving data.
O What is the benefit of using Data Access Object (DAO) Design Pattern? Answer: it allows different storage implementations to be 'plugged in' with minimal impact to the rest of the system.
O What all persistent entity classes require to use hibernate? Answer: An id property holds a unique identifier value for a particular event. We usually do not manipulate the identity of an object, hence the setter method should be private. The no-argument constructor is a requirement for all persistent classes.
O What is the use of hibernate mapping file? Answer: Hibernate needs to know how to load and store objects of the persistent class. This is where the hibernate mapping file comes into play. The mapping file tells hibernate what table in the database it has to access, and what columns in that table it should use.
O Where can you find the hibernate DTD file? Answer: Hibernate-core.jar includes the DTD file.
O Pow do you speclfy Lhe ldenLlfler (prlmary key) generaLlon sLraLegy? Answer uslng Lhe nesLed f Lag ln slde /class/ld xpaLh
O Pow do you speclfy Lhe properLles of an enLlLy class? Answer uslng Lhe Lag
O JhaL aLLrlbuLe ln Lhe ld/properLy elemenL Lells PlbernaLe whlch geLLer and seLLer meLhods Lo use? Answer name aLLrlbuLe
O JhaL happens lf you do noL speclfy Lhe column aLLrlbuLe? Answer PlbernaLe by defaulL uses Lhe properLy name as Lhe column name
O JhaL ls hlbernaLe mapplng Lypes? Answer 1he Lypes declared and used ln Lhe mapplng flles are noL !ava daLa Lypes Lhey are noL sql daLa Lypes PlbernaLe wlll Lry Lo deLermlne Lhe correcL converslon and mapplng Lype lLself lf Lhe Lype aLLrlbuLe ls noL presenL ln Lhe mapplng
O JhaL ls Lhe lssue wlLh auLomaLlc deLecLlon of Lype uslng 8eflecLlon on Lhe !ava class ? Answer PlbernaLe cannoL know lf Lhe properLy whlch ls of [avauLlluaLe should map Lo a SCL daLe LlmesLamp or Llme column 1herefore musL be speclfled
O JhaL ls a sesslon facLory? Answer SesslonlacLory ls a global facLory responslble for a parLlcular daLabase lf you have several daLabases for easler sLarLup you should use several sesslonfacLory conflguraLlon ln several conflguraLlon flles
O Pow do you sLarL up hlbernaLe? Answer by bulldlng a global orghlbernaLeSesslonlacLory ob[ecL and sLorlng lL somewhere for easy access ln appllcaLlon code A orghlbernaLeSesslonlacLory ls used Lo obLaln orghlbernaLeSesslon lnsLances A orghlbernaLeSesslon represenLs a slngleLhreaded unlL of work
O JhaL are Lhe logln cholces for hlbernaLe? Answer log4[ and !uk 14 logglng
O Pow PlbernaLe knows Lo lnserL lnLo Lhe daLabase? Answer user creaLes a new LvenL Cb[ecL and handed lL over Lo PlbernaLe AL LhaL polnL PlbernaLe Lakes care of Lhe SCL and execuLes an lnSL81 on Lhe daLabase
O JhaL does sesslonlacLorygeLCurrenLSesslon () does? Answer lL always reLurns Lhe currenL unlL of work lf you swlLch Lhe conflguraLlon opLlon for Lhls mechanlsm Lo Lhread" Lhe conLexL of a currenL unlL of work ls bound Lo Lhe currenL !ava Lhread LhaL execuLes Lhe appllcaLlon
O Pow Lhe orghlbernaLeSesslon unblnds lLself? Answer Lhrough commlL or rollback PlbernaLe closes lL for Lhe user
O JhaL would be Lhe vlslblllLy for Lhe properLles ln your !ava8ean? Answer rlvaLe
O Pow PlbernaLe creaLe ob[ecLs for your !ava8ean? Answer uslng !ava 8eflecLlon
O Pow do you Lurn on/off auLomaLlc generaLlon of daLabase schema lnLo Lhe daLabase? Answer 1he hbm2ddlauLo opLlon Lurn on auLomaLlc generaLlon of daLabase schemas dlrecLly lnLo Lhe daLabase 1hls can also be Lurned off by removlng Lhe conflguraLlon opLlon or redlrecLed Lo a flle wlLh Lhe help of SchemaLxporL AnL Lask
O JhaL meLhod blnds a sesslon Lo PlbernaLe? Answer geLCurrenLSesslon ()
O JhaL are Lhe deslgn quesLlons you have Lo deal wlLh? Answer ulrecLlonallLy mulLlpllclLy and collecLlon behavlor
O Pow mulLl valued assoclaLlons are represenLed ln PlbernaLe? Answer by one of Lhe !ava CollecLlon lramework conLracLs
O Pow do you enable manyLomany relaLlonshlp? Answer uslng manyLomany Lag
O JhaL ls Lhe use of an assoclaLlon Lable? Answer for a manyLomany relaLlonshlp Lach row ln Lhls Lable represenLs a llnk beLween a person and an evenL 1he Lable name ls declared uslng Lhe Lable aLLrlbuLe of Lhe seL elemenL 1he assoclaLlon Lable ls baslcally conslsLs of prlmary keys
O JhaL does lL mean by a perslsLence sLaLe of an ob[ecL? Answer LhaL lL ls bound Lo a parLlcular hlbernaLe orghlbernaLeSesslon
O JhaL ls flushlng ln PlbernaLe? Answer Lhe process of synchronlzlng Lhe memory sLaLe wlLh Lhe daLabase usually only aL Lhe end of unlL of work ls called flushlng
O JhaL ls a deLached sLaLe of an ob[ecL? Answer lf an ob[ecL was ln perslsLence sLaLe before and noL perslsLence now ( LhaL ls ouLslde of orghlbernaLeSesslon) Lhen lL ls called Lo be ln a deLached sLaLe AnyLhlng done ln beLween Lwo commlLs are ln deLached sLaLe
O JhaL ls Lhe use of sesslonupdaLe ()? Answer Lhe call Lo updaLe makes a deLached ob[ecL perslsLenL agaln by blndlng lL Lo a new unlL work so any modlflcaLlon you made lL Lo whlle deLached can be saved Lo Lhe daLabase 1hls lncludes any modlflcaLlons (addlLlon /deleLlons) you made Lo a collecLlon of LhaL enLlLy ob[ecL
O Pow can you Lell hlbernaLe LhaL Lhe collecLlon does noL conLaln reference Lo anoLher enLlLy? Answer 8y uslng Lhe elemenL Lag
O Jhlch case ls used by PlbernaLe mapplng Lype/converLer? Answer lower case
O JhaL does bldlrecLlonal assoclaLlon means? Answer A change mode ln one slde of an assoclaLlon ls lnsLanLly reflecLed aL Lhe oLher slde
O Pow do you deLermlne Lhe dlrecLlon of an assoclaLlon? Answer dependlng whlch *hbmxml flle you are addlng Lhe assoclaLlon
O JhaL ls essenLlal Lo achleve bldlrecLlonal/unldlrecLlonal assoclaLlon? Answer you need Lo have collecLlon Lype of boLh sldes All bldlrecLlonal references has one slde as lnverse"
O JhaL happens lf problems occurred durlng processlng or renderlng? Answer an excepLlon wlll be Lhrown and Lhe daLabase LransacLlon rolls back
O Sesslon lacLory ( orghlbernaLeSesslonlacLory ) A Lhreadsafe lmmuLable cache of complled mapplngs for a slngle daLabase A lacLory for Sesslon and a cllenL of ConnecLlonrovlder SesslonlacLory can hold an opLlon cache of daLa LhaL ls reusable beLween LransacLlons aL a process or clusLer level
O Sesslon ( orghlbernaLeSesslon ) A slngleLhreaded shorLllved represenLlng a conversaLlon beLween Lhe appllcaLlon and Lhe perslsLenL sLore lL wraps a !u8C connecLlon and ls a facLory for LransacLlon Sesslon holds a mandaLory flrsLlevel cache of perslsLenL ob[ecL LhaL are used when navlgaLlng Lhe ob[ecL graph or looklng up ob[ecLs by ldenLlfler
O 1ranslenL and deLached ob[ecLs and collecLlon lnsLances of perslsLenL classes LhaL are noL currenLly assoclaLed wlLh a Sesslon 1hey may have been lnsLanLlaLed by Lhe appllcaLlon and noL yeL perslsLed or Lhey may have been lnsLanLlaLed by a closed Sesslon
O 1ransacLlon (orghlbernaLe1ransacLlon ) A slngle Lhreaded shorLllved ob[ecL used by Lhe appllcaLlon Lo speclfy aLomlc unlLs of work lL absLracLs appllcaLlons from !u8C !1A CC88A eLc
O ConnecLlonrovlder ( orghlbernaLeConnecLlonrovlder) A facLory for and pool of !u8C connecLlons lL absLracLs Lhe appllcaLlon from daLasource or urlverManager
O JhaL ls a deLached ob[ecL? Answer Lhe lnsLance was once assoclaLed wlLh a perslsLence conLexL buL LhaL conLexL was closed or Lhe lnsLance was serlallzed Lo anoLher process lL has a perslsLenL ldenLlLy and can have a correspondlng row ln Lhe daLabase PlbernaLe does noL guaranLee Lhe relaLlonshlp beLween perslsLenL ldenLlLy and [ava ldenLlLy
O JhaL ls orghlbernaLecfgconflguraLlon? Answer An lnsLance of orghlbernaLecfgConflguraLlon represenLs an enLlre seL of mapplngs of an appllcaLlon's !ava Lypes Lo an SCL daLabase 1he orghlbernaLecfgconflguraLlon ls used Lo bulld an lmmuLable orghlbernaLeSesslonlacLory ?ou can lnsLanLlaLe by provldlng Lhe locaLlon of Lhe xml mapplng flle 1he orghlbernaLecfgConflguraLlon ls LreaLed as a sLarLup Llme ob[ecL whlch wlll be dlscarded once Lhe SesslonlacLory ls creaLed
O JhaL are Lhe ways Lo pass conflguraLlon properLles Lo PlbernaLe? Answer ass an lnsLance of [avauLllroperLles Lo ConflguraLlonseLroperLles () lace a flle names hlbernaLeproperLles ln a rooL dlrecLory of Lhe classpaLh SeL SysLem properLles uslng [ava uproperLyvalue lnclude properLy elemenL ln hlbernaLecgxml
O Jhen lL ls useful Lo lnsLanLlaLe more Lhan one orghlbernaLeSesslonlacLory ? Answer when you use more Lhan one daLabase
O Pow can you dlsable ouLer [oln feLchlng? Answer by seLLlng Lhe properLy hlbernaLemax_feLch_depLh Lo 0m A seLLlng of 1 or hlgher enables ouLer [oln feLchlng for oneLoone and manyLoone assoclaLlons LhaL have been mapped wlLh feLch"[oln"
O JhaL does orghlbernaLecfgnamlngSLraLegy do ? Answer 1he lnLerface allows you Lo speclfy a namlng sLandard" for daLabase ob[ecLs and schema elemenLs
O JhaL does C!C Means? Answer laln Cld !ava Cb[ecL
O JhaL are Lhe rules for creaLlng a perslsLence class? Answer has a defaulL noargumenL consLrucLor wlLh aL leasL package vlslblllLy rovlde an ldenLlfler properLy ( opLlonal ) refer nonflnal classes ueclare accessors and muLaLors for perslsLenL flelds (opLlonal )
O JhaL should you do lf you lnLend Lo puL lnsLances ln perslsLenL classes ln a seL Lo make use of many valued assoclaLlon? Answer overrlde equals () and hashCode () meLhod
O JhaL ls Lhe besL way Lo overrlde equal () and hashCode () meLhods? Answer use 8uslness key equallLy
O JhaL ls Lhe downslde of dynamlc mapplng over C!C? Answer you lose complleLlme Lype checklng and wlll llkely deal wlLh many excepLlons aL runLlme
O JhaL ls a 1upllzers? Answer lf a glven plece of daLa ls LhoughL of as a daLa sLrucLure Lhen a Lplllzer ls Lhe Lhlng LhaL knows how Lo creaLe such a daLa sLrucLure and how Lo exLracL values from and ln[ecL values lnLo such daLa sLrucLure
O JhaL ls Lhe problem wlLh granularlLy ln C8M perslsLence? Answer CranularlLy refers Lo Lhe relaLlve slze of Lhe ob[ecL s you are worklng wlLh
O JhaL ls a polymorphlc assoclaLlon? Answer when a class ls assoclaLed wlLh a superclass of so many subclasses LhaL assoclaLlon ls polymorphlc assoclaLlon because lL ls noL posslble Lo know ln runLlme whlch subclass LhaL class ls assoclaLed wlLh 1he SCL querles deal wlLh Lhese slLuaLlons are called polymorphlc querles
O Pow many noLlons of sameness are Lhere ln !ava Cb[ecL? Answer Cb[ecL ldenLlLy ( roughly equlvalenL memory locaLlon checked by ab) LquallLy as deLermlned by Lhe lmplemenLaLlon of Lhe equals () meLhods
O JhaL ls a surrogaLe key? Answer A surrogaLe key ls a prlmary key wlLh no meanlng Lo Lhe user ( llke 8lCln1 )
O Pow do you declare a class as a perslsLenL C!C class? Answer uslng Lhe [LnLlLy AnnoLaLlon
O Pow do you declare Lhe ldenLlfler properLy of an enLlLy? Answer uslng Lhe [ld annoLaLlon
O Pow do you blnd a C!C wlLh a daLabase Lable? Answer uslng Lhe [1able annoLaLlon
O JhaL klnd of Cache ls offered by PlbernaLe? Answer PlbernaLe offers naLurally a flrsL level cache for enLlLles called a perslsLence conLexL vla Lhe noLlon of Sesslon 1hls cache ls conLexLual Lo Lhe use case aL hand
O JhaL does lL mean by flrsL level cache and second level cache? Answer llrsL level Cache always assoclaLes wlLh Lhe sesslon ob[ecL Second level cache assoclaLe wlLh Lhe SesslonlacLory Cb[ecL so lL ls noL bound Lo any slngle user 1he cache ls avallable for Lhe enLlre llfeLlme (unLll Lhe appllcaLlon shuLs down) of Lhe appllcaLlon
O JhaL does [lllLeruef do? Answer [orghlbernaLeannoLaLlonslllLeruefs or [lllLeruefs deflnes fllLer deflnlLlon used by fllLer uslng Lhe same name A fllLer ueflnlLlon has a name () and an array of parameLers () A parameLer wlll allow you Lo ad[usL Lhe behavlor of Lhe fllLer aL runLlme Lach parameLer ls deflned by a [aramuef whlch has a name and a Lype
O ln whlch case PlbernaLe may noL be Lhe ldeal soluLlon? Answer PlbernaLe ls noL Lhe besL soluLlon for daLa cenLrlc appllcaLlons LhaL only uses Lhe sLoredprocedures Lo lmplemenL Lhe buslness loglc ln daLabase
O JhaL are Lhe query faclllLles avallable ln PlbernaLe 30? Answer PlbernaLe Cuery Language PlbernaLe CrlLerla Cuery Al and naLlve SCL dlalecL
O JhaL ls Lhe dlfference beLween a perslsLence class ln PlbernaLe and LhaL ln L!8? Answer a perslsLence class can be used ln any execuLlon conLexL aL all no speclal conLalner ls needed
O JhaL ls auLomaLlc dlrLy checklng ln hlbernaLe? Answer lL saves us Lhe efforL of expllclLly asklng PlbernaLe Lo updaLe Lhe daLabase where we modlfy Lhe sLaLe of an ob[ecL lnslde a LransacLlon
O JhaL ls cascadlng save? Answer when a new ob[ecL ls made perslsLenL by noL expllclLly calllng save () meLhod
O JhaL ls LransacLlonalwrlLe behlnd? Answer PlbernaLe uses a sophlsLlcaLed algorlLhm Lo deLermlne an efflclenL orderlng LhaL avolds daLabase forelgn key consLralnL vlolaLlon buL ls sLlll sufflclenLly predlcLable Lo Lhe user 1hls ls called LransacLlonal wrlLebehlnd
O ls PlbernaLe sesslon Lhreadsafe? Answer no lL should be used one Lhread aL a Llme
O Jhere does an appllcaLlon geL sesslon lnsLance from? Answer 1he appllcaLlon geLs a sesslon lnsLance from Lhe SesslonlacLory lnLerface
O JhaL ls a second level cache ln PlbernaLe? Answer 1he SesslonlacLory cache generaLe SCL sLaLemenLs and oLher mapplngs meLadaLa LhaL PlbernaLe uses aL runLlme lL also holds cached daLa has been read ln one unlL of work and may be reused ln a fuLure unlL of work ( only lf class and collecLlon mapplngs speclfy LhaL Lhls second level cache ls deslrable)
O Can you use an lnsLance of Cuery lnLerface ouLslde a Sesslon? Answer no O What is a Hibernate Type? Answer: A hibernate Type object maps a java type to a database column type (actually, the type may span multiple columns ). All persistence properties of persistence classes, including associations, have a corresponding Hibernate type, This design makes hibernate extremely flexible and extensible.
O How can you map your own type with Hibernate Type object? Answer: Using the UserType and CompositeUserType.
O What is the conventional name for a Hibernate mapping file? Answer: *.hbm.xml
O What are the two ways to add mapping files? Answer: using the addClass () and addResource() methods.
O Why is it important to use a connection pool to obtain connection? Answer: acquiring a new connection is expensive, maintain many idle connections is expensive, creating prepared statements is also expensive for some drivers.
O What is the default connection pool supported by Hibernate? Answer: C3P0.