Hibernate Interview
Hibernate Interview
com/
Hibernate is a popular framework of Java which allows an efficient Object Relational mapping
using configuration files in XML format. After java objects mapping to database tables, database
is used and handled using Java objects without writing complex database queries.
2. What is ORM?
ORM (Object Relational Mapping) is the fundamental concept of Hibernate framework which
maps database tables with Java Objects and then provides various API's to perform different
types of operations on the data tables.
3. How properties of a class are mapped to the columns of a database table in Hibernate?
Mappings between class properties and table columns are specified in XML file as in the below
example:
Configuration interface of hibernate framework is used to configure hibernate. It's also used to
bootstrap hibernate. Mapping documents of hibernate are located using this interface.
5. How can we use new custom interfaces to enhance functionality of built-in interfaces
of hibernate?
We can use extension interfaces in order to add any required functionality which isn't supported
by built-in interfaces.
6. Should all the mapping files of hibernate have .hbm.xml extension to work properly?
No, having .hbm.xml extension is a convention and not a requirement for hibernate mapping file
names. We can have any extension for these mapping files.
1/8
http://career.guru99.com/
To create a session factory in hibernate, an object of configuration is created first which refers to
the path of configuration file and then for that configuration, session factory is created as given
in the example below:
[crayon-582f0a988183a736575923/]
8. What are POJOs and what's their significance?
POJOs( Plain Old Java Objects) are java beans with proper getter and setter methods for each
and every properties.
Use of POJOs instead of simple java classes results in an efficient and well constructed code.
9. What's HQL?
HQL is the query language used in Hibernate which is an extension of SQL. HQL is very
efficient, simple and flexible query language to do various type of operations on relational
database without writing complex database queries.
[xml]
{ ? = call selectStudents() }
[/xml]
Criteria is a simple yet powerful API of hibernate which is used to retrieve entities through
criteria object composition.
[xml]
true
2/8
http://career.guru99.com/
[/xml]
3/8
http://career.guru99.com/
[java]
Session s = null;
Transaction tr = null;
try {
s = sessionFactory.openSession();
tr = s.beginTransaction();
doTheAction(s);
tr.commit();
} catch (RuntimeException exc) {
tr.rollback();
} finally {
s.close();
}
[/java]
4/8
http://career.guru99.com/
a. Using HQL
b. Using identifier
c. Using Criteria API
d. Using Standard SQL
[xml]
[/xml]
Objects which have been detached and are no longer associated with any persistent entities
can be reattached by calling session.merge() method of session class.
31. What are different ways to disable hibernate second level cache?
Hibernate second level cache can be disabled using any of the following ways:
a. By setting use_second_level_cache as false.
b. By using CACHEMODE.IGNORE
c. Using cache provider as org.hibernate.cache.NoCacheProvider
5/8
http://career.guru99.com/
[xml]
[/xml]
40. 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]
[/xml]
[java]
6/8
http://career.guru99.com/
[/java]
41. 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.
7/8
http://career.guru99.com/
8/8
Powered by TCPDF (www.tcpdf.org)