Interview Questions.

Best Hibernate Interview Questions and Answers 2018 - Jul 17, 2022


Best Hibernate Interview Questions and Answers 2018

Q1. What’s Hibernate?

Ans: Hibernate is a popular framework of Java which lets in an efficient Object Relational mapping the usage of configuration documents in XML format. After java gadgets mapping to database tables, database is used and dealt with the use of Java items with out writing complicated database queries.

Q2. What is ORM?

Ans: ORM (Object Relational Mapping) is the fundamental concept of Hibernate framework which maps database tables with Java Objects after which provides diverse API’s to perform extraordinary types of operations at the records tables.

Q3. How homes of a class are mapped to the columns of a database table in Hibernate?

Ans: Mappings between magnificence residences and table columns are specified in XML document as within the beneath example:

Q4. What’s the usage of Configuration Interface in hibernate?

Ans: Configuration interface of hibernate framework is used to configure hibernate. It’s extensively utilized to bootstrap hibernate. Mapping documents of hibernate are placed the use of this interface.

Q5. How can we use new custom interfaces to beautify capability of built-in interfaces of hibernate?

Ans: We can use extension interfaces so one can upload any required capability which isn’t supported by using built-in interfaces.

Q6. Should all of the mapping documents of hibernate have .Hbm.Xml extension to paintings well?

Ans: No, having .Hbm.Xml extension is a convention and now not a demand for hibernate mapping record names. We could have any extension for those mapping files.

Q7. How will we create session manufacturing unit in hibernate?

Ans: To create a session manufacturing unit in hibernate, an object of configuration is created first which refers back to the direction of configuration document and then for that configuration, session manufacturing unit is created as given in the instance below:





Configuration config = new Configuration ( ) ;

config . AddResource ( & amp ; amp ; quot ; myinstance / configuration . Hbm . Xml & amp ; amp ; quot ; ) ;

config . SetProperties ( System . GetProperties ( ) ) ;

SessionFactory classes = config . BuildSessionFactory ( ) ;

Q8. What are POJOs and what’s their importance?

Ans: POJOs( Plain Old Java Objects) are java beans with proper getter and setter strategies for every and every homes.

Use of POJOs instead of easy java lessons outcomes in an green and properly constructed code.

Q9. What’s HQL?

Ans: HQL is the question language utilized in Hibernate that's an extension of SQL. HQL is very efficient, simple and bendy question language to do diverse kind of operations on relational database without writing complicated database queries.

Q10. How are we able to invoke stored processes in hibernate?

Ans: In hibernate we can execute stored tactics the usage of code as under:


<sql-query name=”getStudents” callable=”true”>

<return alias=”st” class=”Student”>

<return-property name=”std_id” column=”STD_ID”/>

<return-property name=”s_name” column=”STD_NAME”/>

<return-property name=”s_dept” column=”STD_DEPARTMENT”/>

 ? = name selectStudents() 




Q11. What is standards API?

Ans: Criteria is a simple yet powerful API of hibernate that is used to retrieve entities through criteria object composition.

Q12. What are the blessings of the use of Hibernate template?

Ans: Following are a few key advantages of using Hibernate template:

Session last is computerized.

Interaction with hibernate consultation is simplified.

Exception handling is automatic.

Q13. How can we see hibernate generated SQL on console?

Ans: We want to feature following in hibernate configuration file to permit viewing SQL at the console for debugging functions:


<property name=”show_sql”>authentic</property>


Q14. What are the 2 varieties of collections in hibernate?

Ans: Following are the two varieties of collections in hibernate:

Sorted Collection

 Order Collection

Q15. What’s the distinction between session.Shop() and consultation.SaveOrUpdate() techniques in hibernate?

Ans: Sessionsave() method saves a document handiest if it’s unique with respect to its primary key and could fail to insert if primary key already exists in the desk.

SaveOrUpdate() technique inserts a new record if primary key's unique and will replace an current report if number one key exists in the desk already.

Q16. What the advantages are of hibernate over JDBC?


Hibernate can be used seamlessly with any sort of database as its database independent while in case of JDBC, developer has to jot down database particular queries.

Using hibernate, developer doesn’t need to be an professional of writing complex queries as HQL simplifies question writing process whilst in case of JDBC, its activity of developer to write down and track queries.

In case of hibernate, there's no want to create connection pools as hibernate does all connection dealing with robotically at the same time as in case of JDBC, connection swimming pools need to be created.

Q17. How can we get hibernate records?

Ans: We can get hibernate records the usage of getStatistics() approach of SessionFactory magnificence as proven below:


Q18. What is brief example state in Hibernate?

Ans: If an instance is not related to any continual context and additionally, it has in no way been related to any chronic context, then it’s said to be in transient country.

Q19. How are we able to lessen database write movement times in Hibernate?

Ans: Hibernate offers grimy checking feature which can be used to reduce database write instances. Dirty checking feature of hibernate updates handiest those fields which require a trade whilst keeps others unchanged.

Q20. What’s using callback interfaces in hibernate?

Ans: Callback interfaces of hibernate are beneficial in receiving event notifications from gadgets. For instance, while an item is loaded or deleted, an event is generated and notification is sent using callback interfaces.

Q21. When an example is going in indifferent country in hibernate?

Ans: When an example become in advance related to a few continual context (e.G. A desk) and is no longer associated, it’s known as to be in detached state.

Q22. What the 4 ORM degrees are in hibernate?

Ans: Following are the 4 ORM levels in hibernate:

Pure Relational

Light Object Mapping

Medium Object Mapping

Full Object Mapping

Q23. What’s transaction management in hibernate? How it works?

Ans: Transaction management is the system of managing a set of statements or commands. In hibernate; transaction management is accomplished by means of transaction interface as proven in under code:


Session s = null;

Transaction tr = null;


s = sessionFactory.OpenSession();

tr = s.BeginTransaction();



 catch (RuntimeException exc) 


 sooner or later 




Q24. What the 2 methods are of hibernate configuration?

Ans: We can use any of the subsequent  methods of hibernate configuration:

XML based configuration ( using hibernate.Cfg.Xml document)

Programmatic configuration ( Using code common sense)

Q25. What is the default cache service of hibernate?

Ans: Hibernate supports a couple of cache services like EHCache, OSCache, SWARMCache and TreeCache and default cache carrier of hibernate is EHCache.

Q26. What are the two mapping associations used in hibernate?

Ans: In hibernate; we have following  styles of mapping associations among entities:

One-to-One Association

Many-to-Many Association

Q27. What’s using Hibernate QBC API?

Ans: Hibernate Query By Criteria (QBC) API is used to create queries by using manipulation of standards items at runtime.

Q28. In what number of ways, objects can be fetched from database in hibernate?

Ans: Hibernate gives following 4 approaches to fetch items from database:

Using HQL

Using identifier

Using Criteria API

Using Standard SQL

Q29. How number one key's created by way of the use of hibernate?

Ans: Database primary secret is certain in the configuration file hbm.Xml. Generator can also be used to specify how number one key's being created within the database.

In the below example, deptId acts as number one key:


<id name=”deptId” type=”string” >

<column name=”columnId” length=”30″/>




Q30. How can we reattach any indifferent objects in Hibernate?

Ans: Objects which have been indifferent and are not associated with any chronic entities can be reattached with the aid of calling session.Merge() approach of consultation class.

Q31. What are distinct ways to disable hibernate second degree cache?

Ans: Hibernate 2nd degree cache may be disabled the use of any of the following approaches:

By putting use_second_level_cache as fake.


Using cache provider as org.Hibernate.Cache.NoCacheProvider

Q32. What is ORM metadata?

Ans: All the mapping between lessons and tables, homes and columns, Java kinds and SQL kinds etc is defined in ORM metadata.

Q33. Which one is the default transaction manufacturing unit in hibernate?

Ans: With hibernate 3.2, default transaction factory is JDBCTransactionFactory.

Q34. What’s the function of JMX in hibernate?

Ans: Java Applications and components are controlled in hibernate by using a trendy API called JMX API. JMX presents gear for improvement of efficient and strong allotted, web primarily based answers.

Q35. How are we able to bind hibernate consultation factory to JNDI?

Ans: Hibernate session manufacturing unit may be sure to JNDI by way of making configuration modifications in hibernate.Cfg record.

Q36. In what number of approaches items can be identified in Hibernate?

Ans: Object identity can be executed in hibernate in following three approaches:

Using Object Identity: Using == operator.

Using Object Equality: Using equals() technique.

Using database identification: Relational database objects may be diagnosed if they constitute equal row.

Q37. What special fetching techniques are of hibernate?

Ans: Following fetching strategies are available in hibernate:

Join Fetching

Batch Fetching

Select Fetching

Sub-select Fetching

Q38. How mapping of java objects is completed with database tables?

Ans: To map java items with database tables, we want to have Java beans properties names same as column names of a database desk. Then mapping is furnished in hbm.Xml file as given under:



<class name=”Student”  table=”tbl_student”>

<property  column=”studentname” length=”255″

name=”studentName” not-null=”true”  type=”java.Lang.String”/>

<property  column=”studentDisciplne” length=”255″

name=”studentDiscipline” not-null=”true”  type=”java.Lang.String”/>




Q39. What are derived houses in hibernate?

Ans: Derived houses are those houses which are not mapped to any columns of a database desk. Such homes are calculated at runtime through evaluation of any expressions.

Q40. What is supposed by means of a Named SQL Query in hibernate and the way it’s used?

Ans: Named SQL queries are those queries which might be defined in mapping record and are known as as required everywhere.

For instance, we will write a SQL question in our XML mapping document as follows:


<sql-query name = “studentdetails”>

<return alias=”std”/>



FROM Student std WHERE std.NAME LIKE :name



Then this question may be called as follows:


List college students = session.GetNamedQuery(&amp;quot;studentdetails&amp;quot;)

.SetString(&amp;quot;TomBrady&amp;quot;, name)




Q41. What’s the difference among load() and get() method in hibernate?

Ans: Load() methods results in an exception if the specified facts isn’t determined inside the database while get() approach returns null while records against the identity isn’t observed within the database.

So, preferably we must use Load() technique most effective when we're certain about lifestyles of facts towards an identification.

Q42. What’s the usage of version belongings in hibernate?

Ans: Version assets is used in hibernate to recognize whether or not an item is in transient country or in indifferent nation.

Q43. What is characteristic orientated programming?

Ans: In Attribute orientated programming, a developer can add Meta data (attributes) in the java supply code to add greater significance inside the code. For Java (hibernate), attribute oriented programming is enabled by an engine known as XDoclet.

Q44. What’s the usage of session.Lock() in hibernate?

Ans: consultation.Lock() method of session magnificence is used to reattach an item which has been detached in advance. This technique of reattaching doesn’t take a look at for any records synchronization in database at the same time as reattaching the object and for this reason might also lead to lack of synchronization in information.

Q45. Does hibernate help polymorphism?

Ans: Yes, hibernate absolutely helps polymorphism. Polymorphism queries and polymorphism institutions are supported in all mapping strategies of hibernate.

Q46. What the three inheritance fashions are of hibernate?

Ans: Hibernate has following three inheritance fashions:

Tables Per Concrete Class

Table consistent with class hierarchy

Table consistent with sub-elegance

Q47. How can we map the training as immutable?

Ans: If we don’t want an application to replace or delete items of a class in hibernate, we can make the elegance as immutable through placing mutable=fake

Q48. What’s general hibernate go with the flow the use of RDBMS?

Ans: General hibernate drift regarding RDBMS is as follows:

Load configuration file and create item of configuration elegance.

Using configuration item, create sessionFactory object.

From sessionFactory, get one session.

Create HQL question.

Execute HQL query and get the effects. Results may be in the form of a list.

Q49. What is Light Object Mapping?

Ans: Light Object Mapping is one of the ranges of ORM first-class wherein all entities are represented as classes and they're mapped manually.

Q50. What’s distinction between managed institutions and hibernate institutions?

Ans: Managed institutions relate to container management endurance and are bi-directional whilst hibernate institutions are unidirectional.