10:14 pm - Friday March 22, 2019

Hibernate Interview Questions and Answers – Part 2

Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

1. Define HibernateTemplate?

org.springframework.orm.hibernate.HibernateTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.

2. What are the benefits does HibernateTemplate provide?

The benefits of HibernateTemplate are :

  • HibernateTemplate, a Spring Template class simplifies interactions with Hibernate Session.
  • Common functions are simplified to single method calls.
  • Sessions are automatically closed.
  • Exceptions are automatically caught and converted to runtime exceptions.

3. How do you switch between relational databases without code changes?

Using Hibernate SQL Dialects, we can switch databases. Hibernate will generate appropriate hql queries based on the dialect defined.

4. If you want to see the Hibernate generated SQL statements on the console, what should we do?

In Hibernate configuration file set as follows:

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

5. What are derived properties?

The properties that are not mapped to a column, but calculated at runtime by evaluation of expression are called derived properties. The expression can be defined using the formula attribute of the element.

6. What is the difference between sorted and ordered collection in hibernate?


Sorted collection

 Order collection

 A sorted collection is sorting a collection by utilizing the sorting features provided by the Java collections framework. The sorting occurs in the memory of JVM which running Hibernate after the data being read from the database using java comparator.

 Order collection is sorting a collection by specifying the order-by clause for sorting this collection when retrieval.

 If your collection is not large, it will be a more efficient way to sort it.

 If your collection is very large, it will be a more efficient way to sort it.

7. what are the Collection types in Hibernate?

  • Bag
  • Set
  • List
  • Array
  • Map

8. What is Hibernate proxy?

The proxy attribute enables lazy initialization of persistent instances of the class. Hibernate will initially return CGLIB proxies which implement the named interface. The actual persistent object will be loaded when a method of the proxy is invoked.

9. What is component mapping in Hibernate?

  • A component is an object saved as a value, not as a reference.
  • A component can be saved directly without needing to declare interfaces or identifier properties.
  • Required to define an empty constructor.
  • Shared references not supported.


10. What are the ways to express joins in HQL?

HQL provides four ways of expressing (inner and outer) joins:-

  • An implicit association joins.
  • An ordinary join in the FROM clause.
  • A fetch join in the FROM clause.
  • A theta-style join in the WHERE clause.


PARTS : >  1   2   3    4   5   6   7   8   9  10  11  12

Filed in: Z-A Interview Questions

No comments yet.

Leave a Reply