Hibernate Interview Questions And Answers

 

Q1. What is Hibernate Framework?


What is Hibernate Framework
What is Hibernate Framework




Q2. Explain hibernate Architecture?

Explain hibernate Architecture
Explain hibernate Architecture




Q3. What is the difference between Get and Load method?

What is the difference between Get and Load method
What is the difference between Get and Load method




Q4. What are the advantages of using Hibernate?

What are the advantages of using Hibernate
What are the advantages of using Hibernate




Q5. What are the advantages of using Hibernate over JDBC?

What are the advantages of using Hibernate over JDBC
What are the advantages of using Hibernate over JDBC

Q6. How to configure one-to-one mapping in hibernate using xml and annotations?

We can do the same using xml and annotations very easily. Lets's take an example for our understanding. Say we have an employee and an address for our example. According one-to-one mapping an employee will have one address and vice versa.

XML: In this case, we will have two xml files lets's say employee.hbm.xml and address.hbm.xml. In this files we will mention the class we will mention the address in the <one-to-one> tag, vice versa. And in the configuration file that is in cfg.xml we will  use the hbm.xml file using the <mapping resource> tag.
The other way to do the same with ANNOTATION

Q7. What is the Criteria in Hibernate?

The Hibernate Criteria Query Language (HCQL) is used to fetch the records based on the specific criteria. The Criteria interface provides methods to apply criteria such as retrieving all the records of the table whose salary is greater than 50000 etc.

Advantage of HCQL
The HCQL provides methods to add criteria, so it is easy for the java programmer to add criteria. The java programmer is able to add many criteria on a query.

Criteria Interface
The Criteria interface provides many methods to specify criteria. The object of Criteria can be obtained by calling the createCriteria() method of Session interface.

Syntax of createCriteria() method of Session interface
public Criteria createCriteria(Class c)  


Q8. What is caching in Hibernate?

Hibernate caching improves the performance of the application by pooling the object in the cache. It is useful when we have to fetch the same data multiple times.

There are mainly two types of caching:
First Level Cache, and Second Level Cache.

First Level Cache
The session object holds the first-level cache data. It is enabled by default. The first-level cache data will not be available to the entire application. An application can use many session objects.

Second Level Cache
SessionFactory object holds the second-level cache data. The data stored in the second-level cache will be available to the entire application. But we need to enable it explicitly.
Different vendors have provided the implementation of Second Level Cache.
EH Cache
OS Cache
Swarm Cache
JBoss Cache

Q9.