20+ Hibernate Interview Questions

20+ Hibernate Interview Questions

Hibernate Interview Questions

1) What is hibernate?
Hibernate is an open-source and lightweight ORM tool that is used to store, manipulate, and retrieve data from the database.

2) What is ORM?
ORM is an acronym for Object/Relational mapping. It is a programming strategy to map object with the data stored in the database. It simplifies data creation, data manipulation, and data access.

3) Explain hibernate architecture?
Hibernate architecture comprises of many interfaces such as Configuration, SessionFactory, Session, Transaction, etc.

 hibernate framework architecture
4) What are the core interfaces of Hibernate?
The core interfaces of Hibernate framework are:

Configuration
SessionFactory
Session
Query
Criteria
Transaction
5) Mention some of the advantages of using ORM over JDBC.
ORM has the following advantages over JDBC:

Application development is fast.
Management of transaction.
Generates key automatically.
Details of SQL queries are hidden.
6) Define criteria in terms of Hibernate.
The objects of criteria are used for the creation and execution of the object-oriented criteria queries.

7) List some of the databases supported by Hibernate.
Some of the databases supported by Hibernate are:

DB2
MySQL
Oracle
Sybase SQL Server
Informix Dynamic Server
HSQL
PostgreSQL
FrontBase

8) List the key components of Hibernate.
Key components of Hibernate are:

Configuration
Session
SessionFactory
Criteria
Query
Transaction

9) Mention two components of Hibernate configuration object.
Database Connection

Class Mapping Setup

10) How is SQL query created in Hibernate?
The SQL query is created with the help of the following syntax:

Session.createSQLQuery

11) What does HQL stand for?
Hibernate Query Language

12) How is HQL query created?
The HQL query is created with the help of the following syntax:

Session.createQuery

13) How can we add criteria to a SQL query?
A criterion is added to a SQL query by using the Session.createCriteria.

14) Define persistent classes.
Classes whose objects are stored in a database table are called as persistent classes.

15) What is SessionFactory?
SessionFactory provides the instance of Session. It is a factory of Session. It holds the data of second level cache that is not enabled by default.

16) Is SessionFactory a thread-safe object?
Yes, SessionFactory is a thread-safe object, many threads cannot access it simultaneously.

17) What is Session?
It maintains a connection between the hibernate application and database.

It provides methods to store, update, delete or fetch data from the database such as persist(), update(), delete(), load(), get() etc.

It is a factory of Query, Criteria and Transaction i.e. it provides factory methods to return these instances.

18) Is Session a thread-safe object?
No, Session is not a thread-safe object, many threads can access it simultaneously. In other words, you can share it between threads.