HIBERNATE Interview Questions for freshers experienced :-
1. What are the benefits of ORM tool?
ORM is helpful in automatically generating keys, managing transaction, hiding SQL queries details, and developing applications in quick manner.
2. Provide the list of collection types in Hibernate?
Set, Map, Bag, List and Array are the different types of collections in Hibernate
3. What are the two cache types in Hibernate?
First level cache and Secondary level cache are the types of cache in Hibernate.
4. What is session interface?
Hibernate session which performs database entities manipulation is represented by session interface. Activities carried on by session interface are handling persistence phases, retrieving the persisted ones, and transaction separations management.
5. List out the core interfaces available in Hibernate?
Criteria, Transaction, Session Factory, Query, Configuration, and Session are the core interfaces available in Hibernate.
6. Describe the steps to create database application using Hibernate?
Steps to create Database application using Hibernate:
- Write the Java object
- Create a mapping file. This displays the relationship between the database and attributes.
- Deploy the Hibernate API to store persistent objects.
7. Provide the list of Hibernate support databases?
HSQL, MySQL, FrontBase, Informix Dynamic Server, DB2, Sybase SQL Server, Oracle, and PostgreSQL are the Hibernate support databases.
8. What are the two (2) components available in Hibernate configuration object?
Class Mapping Setup and Database Connection are the two (2) components of Hibernate configuration object.
9. What is the syntax to create SQL query in Hibernate?
The syntax to create SQL query in Hibernate is “Session.createQuery”.
10. What is the syntax to add criteria to the SQL query?
The syntax to create criteria to the SQL query is “Session.createCriteria”.

11. Do you think the extension ‘.hbm.xml’ is mandatory for all the hibernate mapping file to work properly?
No, the extension ‘.hbm.xml’ is not mandatory for all the hibernate mapping file as it is just a convention.
12. What is POJOs?
POJO stands for Plain Old Java Objects. These are java beans which has proper setter and getter methods for every property. Instead of Java classes, the usage of POJOs leads to a well-constructed and effective code.
13. List out the advantages of Hibernate template?
Hibernate template is useful is automating the exception handling and session closing. Also, you can have a simplified communication with hibernate session.
14. What is session.save() in hibernate?
The method session.save() is used to save a record when it is unique with its related primary key. If the primary key is already existing in the table, this method will not allow to insert.
15. Explain saveOrUpdate() in hibernate?
The method saveOrUpdate() method is helpful in inserting a new record when the primary key is unique. If the primary key is already existing in the table, this method will update the record.
16. What is the syntax to retrieve hibernate statistics?
Use the syntax “SessionFactory.getStatistics()” to retrieve the hibernate statistics.
17. Provide the list of ORM levels available in Hibernate?
Medium Object Mapping, Pure Relational, Full Object Mapping and Light Object Mapping are the ORM levels available in Hibernate.
18. Provide the mapping associations utilized in Hibernate?
One-to-One Association and Many-to-Many Association are the two (2) mapping associations utilized in Hibernate.
19. What are the different methods to fetch objects from database in Hibernate?
In Hibernate, you can use Criteria API, HQL, Standard SQL, and Identifier to fetch objects from database.
20. In Hibernate, what is the method to reattach the detached objects?
Use the method “session.merge()” to attach the detached objects.
21. To disable second level cache in Hibernate, what are the different methods?
To disable second level cache in Hibernate, you can perform any of the following:
- Use CACHEMODE.IGNORE
- Set “use_second_level_cache” to false
- Make use of cache provider as “cache provider as org.hibernate.cache.NoCacheProvider”
22. In Hibernate, which is the default transaction factory?
The default transaction factory with Hibernate 3.2 is JDBCTransactionFactory.
23. Provide the fetching strategies available in Hibernate?
Batch Fetching, Sub-select Fetching, Join Fetching, and Select Fetching are the fetching strategies available in Hibernate.
24. Explain the benefit of version property in Hibernate?
To recognize whether an object is in detached or transient state, version property in Hibernate.
25. Do you think polymorphism is supported by Hibernate?
Yes, hibernate purely and completely supports polymorphism.
26. List out the three (3) inheritance models available in Hibernate?
Table per class hierarchy, Table per sub-class, and Tables Per Concrete Class are the three (3) inheritance models available in Hibernate.
27. What is transaction management?
To manage a set of commands or statement, transaction management is used in Hibernate.
28. What is callback interface in Hibernate?
To obtain even notifications from objects, hibernate callback interfaces are used. Say, for example, an even gets generated when an object is deleted or loaded, and callback interfaces send a notification.
29. Provide the various other ORM frameworks in Hibernate?
The other ORM frameworks in Hibernate are TopLink and EJB from Oracle.
30. List out few Java-based frameworks which is supporting hibernate integration?
Eclipse plug-ins, XDoclet Spring, Maven, and J2EE are the java-based frameworks which are supporting hibernate integration.
31. List out a few properties required to database configuration in standalone condition?
hibernate.connection.url, hibernate.connection.pool_size, hibernate.connection.password, hibernate.connection.driver_class, hibernate.connection.autocommit, hibernate.dialect, and hibernate.connection.username are the few properties required to database configuration in standalone condition.
32. What is the usage of method Session.beginTransaction()?
To start a unit of work and return the allied transaction object, Session.beginTransaction method is used in hibernate.
33. Provide the method to re-read a provided instance state from the underlying database?
To re-read a provided instance state from the underlying database, use the method “Session.refresh”.
34. Do you think the SessionFactory is thread-safe?
Yes, of-course. SessionFactory is a thread-safe and multiple threads can access the same simultaneously.
35. Do you think Session is a thread-safe object?
No, it is not possible.
36. Provide the concurrency strategies in Hibernate?
Non-strict read-write, Transactional, Read-only and Read-write are the concurrency strategies in Hibernate.
37. Define first level cache?
First level cache is an essential cache where we can see all requests are passing. Before committing to the database, the session object maintains an object under its self-power.
38. Explain Query level cache?
A cache is implemented by Hibernate which is for query resultsets, integrating meticulously with the second level cache. This is not a mandatory feature.
39. What is the method get ()?
If no data found, the method get() returns the value as null and it always touches the database. Actual objects are returned by get() method.
40. Explain the method load()?
If not data found, the method() throws an exception as “ObjectNotFoundException”. The load() method is often seen to hit the database and it returns proxy object.
41. Describe lazy loading?
There is a process where the objects are loaded on demand basis. Hibernate 3 is a lazy loading by default. Hence, when parent objects are loaded, child objects will not be loaded.
42. Describe HQL?
Similar to SQL tables, Hibernate Query Language (HQL), which is an Object-Oriented Query language, gets the java objects. HQL is a database independent.
43. Can u mention the element of hbl.xml which helps to create the primary key values automatically?
Yes, the element <generator> helps to create the primary key values automatically.
44. Can u mention the element of hbl.xml which helps to map the property ‘java.util.SortedSet’ in hibernate?
The element <set> is used for mapping and ‘java.util.TreeSet’ is used for initialization.
45. Explain addjar() and addDirectory() method in Hibernate?
The method addjar() and addDirectory() methods plays a vital part in streamlining a set of processes like configuration, layout, refactoring and few more. Users can easily load hibernate documents in Hibernate using these two (2) methods.
46. What is Hibernate tuning?
Optimization of the Hibernate applications performance is called Hibernate tuning. By performing SQL optimization, session management, and data caching, hibernate tuning happens.
47. What is derived properties?
The unmapped properties which gets calculated at runtime via expression evaluation is called derived properties. The derived expression is received from a formula with the corresponding element.
48. What is Dialect?
A single file or a group of code files that irregularly explains the procedure of connecting database to a Java class. In hibernate, a dialect plays a major role of recognizing the information that takes place with the fundamental database.
49. Describe Connection Pool?
The connection pool in hibernate is a group of Database connection objects which are created for handling corresponding communication with the database.
50. Which annotation is used to specify the database table?
The annotation @Table helps in specifying the database table which is allied to the entity.
51. What’s General Hibernate Flow Using Rdbms?
General hibernate flow involving RDBMS is as follows:
- Load configuration file and create object of configuration class.
- Using configuration object, create sessionFactory object.
- From sessionFactory, get one session.
- Create HQL query.
- Execute HQL query and get the results. Results will be in the form of a list.
52. How Can We Map The Classes As Immutable?
If we don’t want an application to update or delete objects of a class in hibernate, we can make the class as immutable by setting mutable=false
53. What The Three Inheritance Models Are Of Hibernate?
Hibernate has following three inheritance models:
- Tables Per Concrete Class
- Table per class hierarchy
- Table per sub-class
54. Does Hibernate Support Polymorphism?
Yes, hibernate fully supports polymorphism. Polymorphism queries and polymorphism associations are supported in all mapping strategies of hibernate.
55. What’s The Use Of Session.lock() In Hibernate?
session.lock() method of session class is used to reattach an object which has been detached earlier. This method of reattaching doesn’t check for any data synchronization in database while reattaching the object and hence may lead to lack of synchronization in data.
56. What Is Attribute Oriented Programming?
In Attribute oriented programming, a developer can add Meta data (attributes) in the java source code to add more significance in the code. For Java (hibernate), attribute oriented programming is enabled by an engine called XDoclet.
57. What’s The Use Of Version Property In Hibernate?
Version property is used in hibernate to know whether an object is in transient state or in detached state.
58. What’s The Difference Between Load() And Get() Method In Hibernate?
Load() methods results in an exception if the required records isn’t found in the database while get() method returns null when records against the id isn’t found in the database.
So, ideally we should use Load() method only when we are sure about existence of records against an id.
59. What Is Meant By A Named Sql Query In Hibernate And How It’s Used?
Named SQL queries are those queries which are defined in mapping file and are called as required anywhere.
For example, we can write a SQL query in our XML mapping file as follows:
[xml]
<sql-query name = “studentdetails”>
<return alias=”std”/>
SELECT std.STUDENT_ID AS {std.STUDENT_ID},
std.STUDENT_DISCIPLINE AS {std.discipline},
FROM Student std WHERE std.NAME LIKE :name
</sql-query>
[/xml]
Then this query can be called as follows:
[java]
List students = session.getNamedQuery(&amp;quot;studentdetails&amp;quot;)
.setString(&amp;quot;TomBrady&amp;quot;, name)
.setMaxResults(50)
.list();
[/java]
60. What Are Different Ways To Disable Hibernate Second Level Cache?
Hibernate second level cache can be disabled using any of the following ways:
- By setting use_second_level_cache as false.
- By using CACHEMODE.IGNORE
- Using cache provider as org.hibernate.cache.NoCacheProvider
