hibernate interview questions part1

46
Hibernate interview Questions Part1 Posted by Stephen thangaraj at 18:28 What is Hibernate? Hibernate is a powerful, high performance object/relational persistence and query service.It is an open-source technology which fits well both with Java and .NET technologies.Hibernate lets developers write persistence classes with hibernate query features of HQL within principles of Object Oriented paradigm.It means one can include association,inheritance,polymorphism,composition and collection of these persisting objects to build applications. Hibernate Architecture The main objective of Hibernate is to relieve the developers from manual handling of SQLs,JDBC APIs for resultsets handling and it helps in keeping your data portable to various SQL databases,just by switching the delegate and driver details in hibernate.cfg.xml file. Hibernate offers sophisticated query options, you can write plain SQL, object-oriented HQL (Hibernate Query Language), or create programmatic criteria and example queries. Hibernate can optimize object loading all the time, with various fetching and caching options. Some snapshots of Hibernate: -Free open source -OO Concepts can be implemented. -A rich variety of mappings for collections and dependent objects -No extra code generation or bytecode processing steps in your build procedure -Great performance, has a dual-layer cache architecture, and may be used in a cluster -Its own query language support -Efficient transaction handling -The Java Persistence API is the standard object/relational mapping and persistence management interface of the Java EE 5.0 platform which are implemented with the Hibernate Annotations and Hibernate EntityManager modules, on top of the Hibernate Core.(As part of EJB3.0 spec) Why Hibernate? The reasons are plenty,weighing in favor of Hibernate clearly. -Cost effective.Just imagine when you are using EJBs instead of Hibernate.One has to invest in Application Server(Websphere,Weblogic etc.),learning curve for EJB is slow and requires special training if your developers are not equipped with the EJB know-how. -The developers get rid of writing complex SQLs and no more need of JDBC APIs for resultset handling.Even less code than JDBC.In

Upload: manoj-prabhakar

Post on 16-Aug-2015

230 views

Category:

Documents


1 download

DESCRIPTION

java hibernate interview questions

TRANSCRIPT

Hibernate interview Questions Part1 Posted by Stephen thangaraj at 18:28 What is Hibernate?Hibernate is a powerful, high performance object/relational persistence and uery ser!ice"#t is anopen$source technologywhichfits well bothwith%a!aand"&'(technologies"Hibernate letsde!eloperswritepersistenceclasseswithhibernateueryfeaturesofH)*withinprinciplesof+bject +riented paradigm"#t means one can includeassociation,inheritance,polymorphism,composition andcollection of these persisting objects tobuild applications"Hibernate Architecture(he main objecti!e of Hibernate is to relie!e the de!elopers from manual handling of S)*s,%,-./P#s for resultsets handling and it helps in 0eeping your data portable to !arious S)* databases,justby switching the delegate and dri!er details in hibernate"cfg"1ml file"Hibernate offers sophisticatedueryoptions, youcanwrite plainS)*, object$orientedH)*2Hibernate )uery *anguage3, or create programmatic criteria and e1ample ueries" Hibernate canoptimi4e object loading all the time, with !arious fetching and caching options"Some snapshots of Hibernate:$5ree open source$++ .oncepts can be implemented"$/ rich !ariety of mappings for collections and dependent objects$&o e1tra code generation or bytecode processing steps in your build procedure$6reat performance, has a dual$layer cache architecture, and may be used in a cluster$#ts own uery language support$'fficient transaction handling$(he %a!a Persistence /P# is the standard object/relational mapping and persistence managementinterface of the %a!a '' 7"8 platform which are implemented with the Hibernate /nnotations andHibernate 'ntity9anager modules, on top of the Hibernate .ore"2/s part of '%-:"8 spec3Why Hibernate?(he reasons are plenty,weighing in fa!or of Hibernate clearly"$.ost effecti!e"%ust imagine when you are using '%-s instead of Hibernate"+ne has to in!est in/pplication Ser!er2;ebsphere,;eblogic etc"3,learning cur!e for '%- is slow and reuires specialtraining if your de!elopers are not euipped with the '%- 0now$how"$(he de!elopers get rid of writing comple1 S)*s and no more need of %,-. /P#s for resultsethandling"'!en less code than %,-."#n fact the ++ de!elopers wor0 well when they ha!e to dealwith object then writing lousy ueries"$Highperformance then'%-s2if we gobytheir industryreputation3,whichitself a containermanaged,hea!yweight solution"$Switching to other S)* database reuires few changes in Hibernate configuration file and reuiresleast clutter than '%-s"$'%-itselfhasmodeleditselfonHibernateprincipleinitslatest !ersioni"e" '%-:becauseofapparent reasons"What is ORM ?+bject ehicle as .ar and @tility>an"1" (able per concrete class with unions#n this scenario there will be 2 tables(ables: .ar, @tility>an, here in this case all common attributes will be duplicated"2" (able per class hierarchySingle (able can be mapped to a class hierarchy(here will be only one table in database named =>ehicle= which will represent all attributes reuiredfor all three classes"Here it is be ta0en care of that discriminating columns to differentiate between .ar and @tility>an:" (able per subclassSimply there will be three tables representing >ehicle, .ar and @tility>anQ) How wi(( you configure Hibernate? Answer* (he configuration files hibernate"cfg"1ml 2or hibernate"properties3 and mapping files D"hbm"1ml areused by the .onfiguration class to create 2i"e" configure and bootstrap hibernate3 theSession5actory, whichinturncreates theSessioninstances" Sessioninstances aretheprimaryinterface for the persistence ser!ice"E hibernate"cfg"1ml 2alternati!ely can use hibernate"properties3: (hese two files are used toconfigurethehibernatese!ice2connectiondri!erclass, connection@