Friday, April 21, 2023

Hibernate Interview Question

  What is hibernate ? 

Hibernate is an open source lightweight ORM tools that is used to store, 

manipulate, retrieve data from the database 

 

What is ORM ? 

ORM is an  acronym for Object Relational Mapping. It is a programming strategy to map object with data stored in database. It is simplifies data creation, data manipulation, and data access. 

 

What are the core interface for Hibernate ? 

  1. Configuration 

  2. Session Factory 

  3. Session 

  4. Query 

  5. Criteria 

  6. Transaction 

 

What is Session Factory ? 

Session Factory 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. 

 

Is Session Factory a thread-safe object? 

Yes, Session Factory is a thread-safe object, many threads cannot access it simultaneously. 

 

What is a Session in Hibernate? 

A session is an object that maintains the connection between Java object application and database. Session also has methods for storing, retrieving, modifying or deleting data from database using methods like persist(), load(), get(), update(), delete(), etc. Additionally, It has factory methods to return Query, Criteria, and Transaction objects. 

 

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. 

 

What is the difference between get and load method? 

No. 

get() 

load() 

1) 

Returns null if an object is not found. 

Throws Object Not Found Exception if an object is not found. 

2) 

get() method always hit the database. 

load() method doesn't hit the database. 

3) 

It returns the real object, not the proxy. 

It returns proxy object. 

4) 

It should be used if you are not sure about the existence of instance. 

It should be used if you are sure that instance exists. 

 

 

How to make an immutable class in hibernate? 

If you mark a class as mutable="false", the class will be treated as an immutable class. By default, it is mutable="true". 

 

Static, Final and Access Modifier

  Static Keyword The static keyword in Java is used for memory management mainly. We can apply static keyword with variables, methods, blo...