Top 11 Hibernate Interview Questions And Answers


1) What is Hibernate?

Hibernate is a high-performance Object/Relational persistence and query service, which is licensed under open source GNU. It not only takes care of the mapping from Java classes to database tables, but also provides data query and retrieval facilities. Hibernate is an Object-Relational Mapping (ORM) solution for JAVA.

2) What are the advantages of Hibernate?

Following are the advantages of Hibernate:

● Hibernate takes care of mapping Java classes to database tables using XML files and without writing any line of code.
● Hibernate does not require an application server to operate.
● Provides simple querying of data.
● It provides simple APIs for storing and retrieving Java objects directly to and from the database.
● If there is change in the database or in any table, then you need to change the XML file properties only.
● Hibernate manipulates complex associations of objects of your database.
● Minimizes database access with smart fetching strategies.

3) Which all databases Hibernate supports?

Following are the databases which Hibernate supports:

● Oracle
● HSQL Database Engine
● DB2/NT
● Microsoft SQL Server Database
● PostgreSQL
● Informix Dynamic Server
● Sybase SQL Server
● FrontBase

4) What is configuration object in Hibernate?

Configuration object is the first Hibernate object that will be created in any Hibernate application. It is usually created only once during application initialization. It represents a configuration or properties file required by the Hibernate.

5) What are the components of configuration object in Hibernate?

Following are the key components of configuration object in Hibernate:

Database Connection ? This is handled through one or more configuration files supported by Hibernate. These files are and hibernate.cfg.xml.
Class Mapping Setup ? This component creates the connection between the Java classes and database tables.

6) What is SessionFactory object in Hibernate?

Configuration object is used to create a SessionFactory object which configures Hibernate for the application using the supplied configuration file and allows Session object to be instantiated.

7) Is SessionFactory thread safe in Hibernate?

Yes, SessionFactory is a thread safe object and used by all the threads of an application in Hibernate.

8) How many SessionFactory object we can have per database in Hibernate?

There can be single SessionFactory object per database in Hibernate.

9) What is Session object in Hibernate?

A Session is used to get a physical connection with a database. The Session object is lightweight and designed to be instantiated each time an interaction is needed with the database.

10) What is Transaction object in Hibernate?

Transaction represents a unit of work with the database and most of the RDBMS supports transaction functionality. Transactions in Hibernate are handled by transaction manager.

11) What is Query object in Hibernate?

Query objects use SQL or Hibernate Query Language (HQL) string to retrieve data from the database and create objects. A Query instance is used to bind query parameters, limit the number of results returned by query, and finally to execute it.


Related links:


Related #tags: