Hibernate Interview Questions – Part 1
(Hibernate Interview Questions Part 2)

What is Hibernate?
It is a open source and light weight ORM  tool
It is used to store, retrieve and manipulate the database.


What is ORM?
ORM stands for Object/Relational Mapping
Matching the object with data in database


What is Impedance Mismatch?
Object oriented applications use relational database to store and retrieve the data.
Object oriented application is in class while relational database represent the data in tabular format.
We can access class using Object but in order to access the data in relational database we need to use query.
The differences between Object Oriented and Relational Database is known as Impedance Mismatch



What are the types of Impedance Mismatch?
Granularity:
Difference between number of classes mapped with database tables
Subtypes:
Differences in relationship among the classes and tables in database
Identity:
Refers to how the objects are differentiated in application and relational database.(In database object is differentiated with Primary key, as in Object model it is distinguished based on object identity and equality)
Association:
Difference in linking classes in application and linking of tables in database.(One entity can have reference to another entity, but in relational database linking is done with help of foreign keys)

We use ORM to overcome impedance mismatch by mapping data representations of Object model having data types to relational data model with SQL data types


What are the Features of Hibernate?
ORM
– matches object model and relational database
Supports inheritance, polymorphism, abstraction and collections framework
Transparent Persistence – changes made in object are automatically detected and updated in database
Database Independent
Provides HQL similar to SQL


Explain Hibernate Architecture:
Consists of,
Configuration class:
 An instance of this class is created once during the initialization. This is used for reading and parsing the properties required to connect database and application
SessionFactory Interface:
Created using an object of Configuration class. This is used to create and open session to communicate with database. This is configured separately for each database being connected
Session Interface:
 Created with SessionFactory object and is used to communicate with database
Transaction Interface:
Created with help of Session Object and is used to perform logical unit of work from database
Query Interface:
Used to create query to perform operations in database
Criteria Interface:
Used to create query to perform database operations with conditions


How to create Hibernate Session?
configure():
 This method loads hibernate.cfg.xml file and initializes the object of Configuration class with configuration properties specified in xml file
getProperties():
 Used to fetch the properties  for configuration that are configured in configure()
applySettings():
Uses serviceRegistryBuilder to apply settings fetched from getProperties().
buildSessionFactory():
 Uses configuration object from Configure() and instantiate new SessionFactory Object. (ServiceRegistry object as parameter)

(Hibernate Interview Questions Part 2)


By Sri

4 thoughts on “Hibernate Interview Questions – Part 1”

Leave a Reply

Your email address will not be published. Required fields are marked *