Hibernate Interview Questions Preparation Course
- 1.5 hours on-demand video
- 4 articles
- Full lifetime access
- Access on mobile and TV
- Certificate of Completion
Get your team access to 4,000+ top Udemy courses anytime, anywhere.Try Udemy for Business
- Understand Hibernate concepts
- Learn Hibernate Interview Questions
- Best practices of Hibernate
- Tricky questions on Hibernate
- Gain deep Hibernate knowledge
- Demand higher salary or promotion based on the knowledge gained!
Q. What is Hibernate framework?
Hibernate is a popular Object Relational Mapping (ORM) framework of Java. It helps in mapping the Object Oriented Domain model to Relational Database tables.
Hibernate is a free software distributed under GNU license.
Hibernate also provides implementation of Java Persistence API (JPA).
In simple words, it is a framework to retrieve and store data from database tables from Java.
Q. How will you map the columns of a DB table to the properties of a Java class in Hibernate?
We can map the class properties and table columns by using one of the two ways:
XML: We can map the column of a table to the property of a class in XML file. It is generally with extension hbm.xml
Annotation: We can also use annotations @Entity and @Table to map a column to the property of a class.
Q. Does Hibernate make it mandatory for a mapping file to have .hbm.xml extension?
No. It is a convention to have.hbm.xml extension in the name of a mapping file. It is not a requirement enforced by Hibernate. We can use any other extension of our convenience for this.
Q. What are the steps for creating a SessionFactory in Hibernate?
Steps to create a SessionFactory in Hibernate are:
Configuration: First create a Configuration object. This will refer to the path of configuration file.
Resource: Add config file resource to Configuration object.
Properties: Set properties in the Configuration object.
SessionFactory: Use Configuration object to build SessionFactory.
Configuration config = new Configuration();
config.setProperties( System.getProperties() );
SessionFactory sessions = config.buildSessionFactory();
Q. Why do we use POJO in Hibernate?
POJO stands for Plain Old Java Objects. A POJO is java bean with getter and setter methods for each property of the bean.
It is a simple class that encapsulates an object’s properties and provides access through setters and getters.
Some of the reasons for using POJO in Hibernate are:
POJO emphasizes the fact that this class is a simple Java class, not a heavy class like EJB.
POJO is a well-constructed class, so it works well with Hibernate proxies.
POJO also comes with a default constructor that makes it easier to persist with a default constructor.
Q. What is Hibernate Query Language (HQL)?
Hibernate Query Language is also known as HQL. It is an Object Oriented language. But it is similar to SQL.
HQL works well with persistent objects and their properties. HQL does not work on database tables.
HQL queries are translated into native SQL queries specific to a database.
HQL supports direct running of native SQL queries also. But it creates an issue in Database portability.
Q. How will you call a stored procedure in Hibernate?
Hibernate supports executing not only simple queries but also stored procedure of database. There are three ways to call a stored procedure in Hibernate:
XML mapping file:
We can declare the store procedure inside XML Mapping file. We can call it with getNamedQuery().
Native SQL: We can use Native SQL to call a store procedure query directly. In this example GetEmployees() stored procedure is being called.
Query query = session.createSQLQuery(
We can also mark out stored procedure with @NamedNativeQueries annotation.
Q. What is the use of Dirty Checking in Hibernate?
Dirty Checking is very useful feature of Hibernate for write to database operations. Hibernate monitors all the persistent objects for any changes. It can detect if an object has been modified or not.
By Dirty Checking, only those fields of an object are updated that require any change in them. It reduces the time-consuming database write operations.
Q. What is the purpose of Callback interface in Hibernate?
Callback interface in Hibernate is mainly used for receiving notifications of different events from an object.
Egg. We can use Callback to get the notification when an object is loaded into or removed from database.
Q. What are the different ways to configure a Hibernate application?
There are mainly two ways to configure Hibernate application:
XML based: We can define the Hibernate configuration in an XML file like ibernate.cfg.xml file
Programming based: We can also use code logic to configure Hibernate in our application.
Q. What is Query Cache in Hibernate?
Hibernate provides Query Cache to improve the performance of queries that run multiple times with same parameters.
At times Query Caching can reduce the performance of Transactional processing. By default Query Cache is disabled in Hibernate.
It has to be used based on the benefits gained by it in performance of the queries in an application.
Q. What are the different types of Association mappings supported by Hibernate?
Hibernate supports following four types of Association mappings:
Unidirectional association: This kind of association works in only one direction.
Unidirectional association with join tables
Bidirectional association: This kind of association works in both directions.
Bidirectional association with join tables
Q. What are the different types of Unidirectional Association mappings in Hibernate?
In Hibernate there can be following three types of Unidirectional Association mappings:
Many to one
One to one
One to many
Q. What are the different options to retrieve an object from database in Hibernate?
In Hibernate, we can use one of the following options to retrieve objects from database:
Identifier: We can use load() or get() method and pass the identifier like primary key to fetch an object from database.
HQL: We can create a HQL query and get the object after executing the query.
Criteria API: We can use Criteria API to create the search conditions for getting the objects from database.
Native SQL: We can write native SQL query for a database and just execute it to get the data we want and convert it into desired object.
Q. What is the difference between a Set and a Bag in Hibernate?
A Bag in Hibernate is an unordered collection. It can have duplicate elements. When we persist an object in a bag, there is no guarantee that bag will maintain any order.
A Set in Hibernate can only store unique objects. If we add the same element to set second time, it just replaces the old one. By default a Set is unordered collection in Hibernate.
Q. What is the difference between load() and get() method in Hibernate?
In Hibernate, load() and get() methods are quite similar in functionality.
The main difference is that load() method will throw an ObjectNotFoundException if row corresponding to an object is not found in the database.
On the other hand, get() method returns null value when an object is not found in the database.
It is recommended that we should use load() method only when we are sure that object exists in database.
Q. When should we use get() method or load() method in Hibernate?
As a thumb rule we can follow these guidelines:
We should use get() method when we want to load an object.
We should use load() method when we need a reference to an object without running extra SQL queries.
- Basic Software knowledge
- Familiar with Hibernate
- Internet access
Hibernate is one of the most popular framework for enterprise applications implemented in Java. Big companies like Amazon, Netflix, Google etc use Hibernate based architecture. This course is designed to help you achieve your goals in Hibernate field. Software Engineers with Hibernate knowledge may get more salary than others with similar qualifications without Hibernate knowledge.
In this course, you will learn how to handle interview questions on Hibernate framework in Software Design and Development. I will explain you the important concepts of Hibernate architecture.
You will also learn the benefits and use cases of Hibernate in this course.
What is the biggest benefit of this course to me?
Finally, the biggest benefit of this course is that you will be able to demand higher salary in your next job interview.
It is good to learn Hibernate for theoretical benefits. But if you do not know how to handle interview questions on Hibernate, you can not convert your Hibernate knowledge into higher salary.
What are the topics covered in this course?
We cover a wide range of topics in this course. We have questions on Hibernate best practices, Security. tricky questions etc.
How will this course help me?
By attending this course, you do not have to spend time searching the Internet for Hibernate interview questions. We have already compiled the list of the most popular and the latest Hibernate Interview questions.
Are there answers in this course?
Yes, in this course each question is followed by an answer. So you can save time in interview preparation.
What is the best way of viewing this course?
You have to just watch the course from beginning to end. Once you go through all the videos, try to answer the questions in your own words. Also mark the questions that you could not answer by yourself. Then, in second pass go through only the difficult questions. After going through this course 2-3 times, you will be well prepared to face a technical interview in Hibernate framework.
What is the level of questions in this course?
This course contains questions that are good for a Fresher to an Architect level. The difficulty level of question varies in the course from a Fresher to an Experienced professional.
What happens if Hibernate technology changes in future?
From time to time, we keep adding more questions to this course. Our aim is to keep you always updated with the latest interview questions on Hibernate.
What are the sample questions covered in this course?
Sample questions covered in this course are as follows:
- What is Hibernate framework?
- What is an Object Relational Mapping (ORM)?
- What is the purpose of Configuration Interface in Hibernate?
- What is Object Relational Impedance Mismatch?
- What are the main problems of Object Relational Impedance Mismatch?
- What are the key characteristics of Hibernate?
- Can you tell us about the core interfaces of Hibernate framework?
- How will you map the columns of a DB table to the properties of a Java class in Hibernate?
- Does Hibernate make it mandatory for a mapping file to have .hbm.xml extension?
- What are the steps for creating a SessionFactory in Hibernate?
- Why do we use POJO in Hibernate?
- What is Hibernate Query Language (HQL)?
- How will you call a stored procedure in Hibernate?
- What is Criteria API in Hibernate?
- Why do we use HibernateTemplate?
- How can you see SQL code generated by Hibernate on console?
- What are the different types of collections supported by Hibernate?
- What is the difference between session.save() and session.saveOrUpdate() methods in Hibernate?
- What are the advantages of Hibernate framework over JDBC?
- How can we get statistics of a SessionFactory in Hibernate?
- What is the Transient state of an object in Hibernate?
- What is the Detached state of an object in Hibernate?
- What is the use of Dirty Checking in Hibernate?
- What is the purpose of Callback interface in Hibernate?
- What are the different ORM levels in Hibernate?
- What are the different ways to configure a Hibernate application?
- What is Query Cache in Hibernate?
- What are the different types of Association mappings supported by Hibernate?
- What are the different types of Unidirectional Association mappings in Hibernate?
- What is Unit of Work design pattern?
- In Hibernate, how can an object go in Detached state?
- How will you order the results returned by a Criteria in Hibernate?
- How does Example criterion work in Hibernate?
- How does Transaction management work in Hibernate?
- How can we mark an entity/collection as immutable in Hibernate?
- What are the different options to retrieve an object from database in Hibernate?
- How can we auto-generate primary key in Hibernate?
- How will you re-attach an object in Detached state in Hibernate?
- What is the first level of cache in Hibernate?
- What are the different second level caches available in Hibernate?
- Which is the default transaction factory in Hibernate?
- What are the options to disable second level cache in Hibernate?
- What are the different fetching strategies in Hibernate?
- What is the difference between Immediate fetching and Lazy collection fetching?
- What is ‘Extra lazy fetching’ in Hibernate?
- How can we check is a collection is initialized or not under Lazy Initialization strategy?
- What are the different strategies for cache mapping in Hibernate?
- What is the difference between a Set and a Bag in Hibernate?
- How can we monitor the performance of Hibernate in an application?
- How can we check if an Object is in Persistent, Detached or Transient state in Hibernate?
- What is ‘the inverse side of association’ in a mapping?
- What is ORM metadata?
- What is the difference between load() and get() method in Hibernate?
- When should we use get() method or load() method in Hibernate?
- What is a derived property in Hibernate?
- How can we use Named Query in Hibernate?
- What are the two locking strategies in Hibernate?
- What is the use of version number in Hibernate?
- What is the use of session.lock() method in Hibernate?
- What inheritance mapping strategies are supported by Hibernate?
- Fresher, Software Engineer, Sr. Software Engineer, Member Technical Staff, Expert
- Software Architect, Development Manager, Director
- Anyone who wants to appear in Hibernate interview
- People interested in going up in career!!