YouTube Icon

Interview Questions.

Top 100+ Hibernate Interview Questions And Answers - May 31, 2020

fluid

Top 100+ Hibernate Interview Questions And Answers

Question 1. What’s Hibernate?

Answer :

Hibernate is a popular framework of Java which lets in an efficient Object Relational mapping the use of configuration files in XML layout. After java items mapping to database tables, database is used and treated using Java items without writing complicated database queries.

Question 2. What Is Orm?

Answer :

ORM (Object Relational Mapping) is the fundamental concept of Hibernate framework which maps database tables with Java Objects and then affords diverse API’s to carry out special styles of operations at the information tables.

J2EE Interview Questions
Question 3. What’s The Usage Of Configuration Interface In Hibernate?

Answer :

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

Question four. How Can We Use New Custom Interfaces To Enhance Functionality Of Built-in Interfaces Of Hibernate?

Answer :

We can use extension interfaces so one can add any required functionality which isn’t supported via integrated interfaces.

J2EE Tutorial
Question 5. Should All The Mapping Files Of Hibernate Have .Hbm.Xml Extension To Work Properly?

Answer :

No, having .Hbm.Xml extension is a conference and no longer a demand for hibernate mapping document names. We could have any extension for these mapping files.

Core Java Interview Questions
Question 6. How Do We Create Session Factory In Hibernate?

Answer :

To create a session manufacturing unit in hibernate, an item of configuration is created first which refers to the route of configuration document after which for that configuration, consultation manufacturing unit is created as given in the example under:

configuration config = new Configuration();
config.AddResource("myinstance/configuration.Hbm.Xml");
config.SetProperties( System.GetProperties() );
SessionFactory periods = config.BuildSessionFactory();
Question 7. What Are Pojos And What’s Their Significance?

Answer :

POJOs( Plain Old Java Objects) are java beans with proper getter and setter strategies for every and each residences.
Use of POJOs instead of easy java lessons results in an efficient and well built code.

Core Java Tutorial JSP Interview Questions
Question 8. What’s Hql?

Answer :

HQL is the query language utilized in Hibernate that's an extension of SQL. HQL may be very efficient, easy and flexible question language to do diverse kind of operations on relational database with out writing complex database queries.

Question nine. How Can We Invoke Stored Procedures In Hibernate?

Answer :

In hibernate we will execute saved strategies the use of code as underneath:
[xml]
<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() 
</return>
</sql-query>
[/xml]

Java-Springs Interview Questions
Question 10. What Is Criteria Api?

Answer :

Criteria is a simple yet effective API of hibernate that is used to retrieve entities thru standards item composition.

JSP Tutorial
Question 11. What Are The Benefits Of Using Hibernate Template?

Answer :

Following are some key blessings of the use of Hibernate template:
a. Session last is automated.
B. Interaction with hibernate consultation is simplified.
C. Exception coping with is automatic.

Java Struts Interview Questions
Question 12. How Can We See Hibernate Generated Sql On Console?

Answer :

We want to add following in hibernate configuration record to enable viewing SQL on the console for debugging functions:
[xml]
<property name=”show_sql”>authentic</property>
[/xml]

J2EE Interview Questions
Question 13. What Are The Two Types Of Collections In Hibernate?

Answer :

Following are the 2 forms of collections in hibernate:
a. Sorted Collection
b. Order Collection

 

Java-Springs Tutorial
Question 14. What’s The Difference Between Session.Shop() And Session.Saveorupdate() Methods In Hibernate?

Answer :

Sessionsave() approach saves a document most effective if it’s particular with respect to its number one key and could fail to insert if primary key already exists in the desk.
SaveOrUpdate() technique inserts a new document if primary key is precise and could replace an current report if primary key exists inside the desk already.

Question 15. What The Benefits Are Of Hibernate Over Jdbc?

Answer :

a.Hibernate may be used seamlessly with any kind of database as its database independent whilst in case of JDBC, developer has to write down database particular queries.
B. Using hibernate, developer doesn’t need to be an professional of writing complicated queries as HQL simplifies question writing method whilst in case of JDBC, its task of developer to write down and track queries.
C. In case of hibernate, there may be no need to create connection pools as hibernate does all connection coping with robotically whilst in case of JDBC, connection pools want to be created.

Log4j Interview Questions
Question 16. How Can We Get Hibernate Statistics?

Answer :

We can get hibernate information the usage of getStatistics() technique of SessionFactory magnificence as proven beneath:
SessionFactory.GetStatistics()

Log4j Tutorial
Question 17. What Is Transient Instance State In Hibernate?

Answer :

If an example isn't always associated with any persistent context and additionally, it has in no way been associated with any persistent context, then it’s said to be in temporary nation.

Software Development Lifecycle (SDLC) Interview Questions
Question 18. How Can We Reduce Database Write Action Times In Hibernate?

Answer :

Hibernate gives dirty checking function which can be used to lessen database write instances. Dirty checking feature of hibernate updates handiest those fields which require a exchange at the same time as continues others unchanged.

 

Core Java Interview Questions
Question 19. What’s The Usage Of Callback Interfaces In Hibernate?

Answer :

Callback interfaces of hibernate are useful in receiving event notifications from items. For instance, while an item is loaded or deleted, an occasion is generated and notification is sent the use of callback interfaces.

Software Development Lifecycle (SDLC) Tutorial
Question 20. When An Instance Goes In Detached State In Hibernate?

Answer :

When an example was in advance related to some chronic context (e.G. A table) and is not associated, it’s called to be in indifferent kingdom.

NHibernate Interview Questions
Question 21. What The Four Orm Levels Are In Hibernate?

Answer :

Following are the 4 ORM ranges in hibernate:
a. Pure Relational
b. Light Object Mapping
c. Medium Object Mapping
d. Full Object Mapping

Question 22. What’s Transaction Management In Hibernate? How It Works?

Answer :

Transaction control is the procedure of coping with a fixed of statements or instructions. In hibernate; transaction management is finished via transaction interface as shown in under code:
[java]
Session s = null;
Transaction tr = null;
strive 
s = sessionFactory.OpenSession();
tr = s.BeginTransaction();
doTheAction(s);
tr.Commit();
 trap (RuntimeException exc) 
tr.Rollback();
 in the end 
s.Near();

[/java]

 

NHibernate Tutorial
Question 23. What The Two Methods Are Of Hibernate Configuration?

Answer :

We can use any of the following two methods of hibernate configuration:
a. XML based totally configuration ( the use of hibernate.Cfg.Xml document)
b. Programmatic configuration ( Using code good judgment)

 

Spring MVC Framework Interview Questions
Question 24. What Is The Default Cache Service Of Hibernate?

Answer :

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

JSP Interview Questions
Question 25. What Are The Two Mapping Associations Used In Hibernate?

Answer :

In hibernate; we've got following  styles of mapping institutions among entities:
a. One-to-One Association
b. Many-to-Many Association

 

Spring MVC Framework Tutorial
Question 26. What’s The Usage Of Hibernate Qbc Api?

Answer :

Hibernate Query By Criteria (QBC) API is used to create queries with the aid of manipulation of standards gadgets at runtime.

Apache Struts 2 Interview Questions
Question 27. In How Many Ways, Objects Can Be Fetched From Database In Hibernate?

Answer :

Hibernate affords following four methods to fetch gadgets from database:
a. Using HQL
b. Using identifier
c. Using Criteria API
d. Using Standard SQL

Java-Springs Interview Questions
Question 28. How Primary Key Is Created By Using Hibernate?

Answer :

Database number one key is targeted within the configuration file hbm.Xml. Generator also can be used to specify how primary secret is being created within the database.
In the under instance, deptId acts as primary key:
[xml]
<id name=”deptId” type=”string” >
<column name=”columnId” length=”30″/>
<generator/>
</id>
[/xml]

JAVA Persistence API (JPA) Tutorial
Question 29. How Can We Reattach Any Detached Objects In Hibernate?

Answer :

Objects that have been detached and are not associated with any persistent entities can be reattached by means of calling session.Merge() technique of session elegance.

Spring Aop Interview Questions
Question 30. What Are Different Ways To Disable Hibernate Second Level Cache?

Answer :

Hibernate second stage cache may be disabled the usage of any of the following approaches:
a. By putting use_second_level_cache as false.
B. By the usage of CACHEMODE.IGNORE
c. Using cache issuer as org.Hibernate.Cache.NoCacheProvider

Question 31. What Is Orm Metadata?

Answer :

All the mapping between classes and tables, properties and columns, Java kinds and SQL sorts and so on is described in ORM metadata.

Apache Struts 2 Tutorial
Question 32. Which One Is The Default Transaction Factory In Hibernate?

Answer :

With hibernate three.2, default transaction manufacturing unit is JDBCTransactionFactory.

Question 33. What’s The Role Of Jmx In Hibernate?

Answer :

Java Applications and components are managed in hibernate by using a general API called JMX API. JMX gives gear for development of green and sturdy distributed, web primarily based solutions.

Java Struts Interview Questions
Question 34. How Can We Bind Hibernate Session Factory To Jndi?

Answer :

Hibernate session manufacturing facility may be bound to JNDI by way of making configuration changes in hibernate.Cfg document.

Question 35. What’s Difference Between Managed Associations And Hibernate Associations?

Answer :

Managed institutions relate to field management patience and are bi-directional while hibernate associations are unidirectional.

Question 36. What Is Light Object Mapping?

Answer :

Light Object Mapping is one of the stages of ORM best in which all entities are represented as classes and they are mapped manually.

Log4j Interview Questions
Question 37. What’s General Hibernate Flow Using Rdbms?

Answer :

General hibernate glide involving RDBMS is as follows:
a. Load configuration document and create object of configuration elegance.
B. Using configuration object, create sessionFactory object.
C. From sessionFactory, get one consultation.
D. Create HQL question.
E. Execute HQL query and get the consequences. Results might be within the shape of a listing.

Question 38. How Can We Map The Classes As Immutable?

Answer :

If we don’t need an utility to replace or delete items of a category in hibernate, we will make the elegance as immutable with the aid of setting mutable=fake

Question 39. What The Three Inheritance Models Are Of Hibernate?

Answer :

Hibernate has following three inheritance models:
a. Tables Per Concrete Class
b. Table in keeping with magnificence hierarchy
c. Table per sub-class

Question 40. Does Hibernate Support Polymorphism?

Answer :

Yes, hibernate completely supports polymorphism. Polymorphism queries and polymorphism associations are supported in all mapping techniques of hibernate.

Software Development Lifecycle (SDLC) Interview Questions
Question forty one. What’s The Use Of Session.Lock() In Hibernate?

Answer :

session.Lock() method of session class is used to reattach an object which has been indifferent in advance. This technique of reattaching doesn’t check for any data synchronization in database whilst reattaching the item and therefore may additionally lead to lack of synchronization in records.

Question 42. What Is Attribute Oriented Programming?

Answer :

In Attribute oriented programming, a developer can upload Meta records (attributes) in the java source code to feature extra significance in the code. For Java (hibernate), characteristic oriented programming is enabled via an engine known as XDoclet.

NHibernate Interview Questions
Question forty three. What’s The Use Of Version Property In Hibernate?

Answer :

Version assets is used in hibernate to realize whether an object is in brief country or in detached nation.

 

Question forty four. What’s The Difference Between Load() And Get() Method In Hibernate?

Answer :

Load() strategies outcomes in an exception if the required data isn’t observed within the database at the same time as get() method returns null whilst statistics against the identity isn’t discovered inside the database.
So, ideally we must use Load() method simplest while we're certain approximately lifestyles of data against an identification.

 

Question 45. What Is Meant By A Named Sql Query In Hibernate And How It’s Used?

Answer :

Named SQL queries are those queries which can be defined in mapping report and are referred to as as required everywhere.
For instance, we are able to write a SQL question 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.Area,
FROM Student std WHERE std.NAME LIKE :name
</sql-query>
[/xml]
Then this query can be referred to as as follows:
[java]
List students = session.GetNamedQuery(&amp;quot;studentdetails&amp;quot;)
.SetString(&amp;quot;TomBrady&amp;quot;, name)
.SetMaxResults(50)
.List();
[/java]




CFG