Corporate Training
Request Demo
Click me
Let's Talk
Request Demo

Hibernate Interview Questions and Answers For Experienced

by Venkatesan M, on Apr 7, 2018 2:33:33 PM

Hibernate Interview Questions and Answers For Experienced

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

Ans: Sorted Collection: The sorted collection is a collection that is sorted using the Java collections framework. The sorting is done in the memory of JVM that is running hibernate, soon after reading the data from the database using Java Comparator The less the collection the more the efficient of sorting
Ordered Collection: The order collections will also sorts a collection by using the order by clause for the results fetched.The more the collection, the more efficient of sorting

Q2. Describe your favorite aspect of the Hibernate framework.

Ans: There are a lot to choose from, but I’d say my favorite thing is that Hibernate is that it’s an object-oriented query language.
There are a lot of potential answers to this question. The interviewer just wants to see where your values lie.

Q3. Explain the main difference between Entity Beans and Hibernate.

Ans: Entity beans are to be implemented by containers, classes, descriptors. Hibernate is just a tool that quickly persist the object tree to a class hierarchy in a database and without using a single SQL statement. The inheritance and polymorphism is quite simply implemented in hibernate which is out of the box of EJB and a big drawback.

Q4. What is your least favorite aspect of the Hibernate framework?

Ans: It does a lot of things right, but I often find myself having to write boilerplate code while using Hibernate. The verbosity of the language makes my job more difficult.
Once again, the interviewer wants to see where your values lie.

Q5. Explain the difference between Hibernate and Spring.

Ans: Hibernate is an ORM tool for data persistency. Spring is a framework for enterprise applications. Spring supports hibernate and provides the different classes which are templates that contains the common code.

Q6. Does a Session object use a first-level cache or a second-level cache?

Ans: A Session object uses a first-level cache. You’d use a second-level cache if it was a SessionFactory object.
This is a skills question, which makes sure you’ve spent enough time with the program to know its ins and outs.

Q7. Why hibernate is advantageous over Entity Beans & JDBC?

Ans: An entity bean always works under the EJB container, which allows reusing of the object external to the container. An object can not be detached in entity beans and in hibernate detached objects are supported.
Hibernate is not database dependent where as JDBC is database dependent. Query tuning is not needed for hibernate as JDBC is needed. Data can be placed in multiple cache which is supported by hibernate, whereas in JDBC the cache is to be implemented.

Q8. How do you maintain your technical expertise?

Ans: I take continuing education classes. I also try to read up on books and magazines. Then of course there are conferences — I try and go to at least one or two a year, since they can be so educational.
The interviewer wants to makes sure that you’re willing to maintain your expertise.

Q9. What is the advantage of Hibernate over jdbc?

Ans: The advantages of Hibernate over JDBC are:

  • Hibernate code will work well for all databases, for ex: Oracle,MySQL, etc. where as JDBC is database specific.
  • No knowledge of SQL is needed because Hibernate is a set of objects and a table is treated as an object, where as to work with JDBC, one need to know SQL.
  • Query tuning is not required in Hibernate. The query tuning is automatic in hibernate by using criteria queries, and the result of performance is at its best. Where as in JDBC the query tuning is to be done by the database authors.
  • With the support of cache of hibernate, the data can be placed in the cache for better performance. Where as in JDBC the java cache is to be implemented.

Q10. Name an advantage of using POJOs.

Ans: POJOs — which stand for Plain Old Java Objects — are more efficient than regular java classes.
This is a skills question, which makes sure you’ve spent enough time with the program to know its ins and outs.

Q11. State the role of SessionFactory interface plays in Hibernate.


  • An application obtains Session instances from a SessionFactory which is typically single for the whole application created during its initialization.
  • The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime.
  • It also holds cached data that has been read in one unit of work and may be reused in a future unit of work
    SessionFactory sessionFactory = configuration.buildSessionFactory();


Q12. Name Hibernate’s two different types of collections.

Ans: There’s Order Collection and Sorted Collection.
This is a skills question, which makes sure you’ve spent enough time with the program to know its ins and outs.

Q13. What is Hibernate Query Language (HQL)?

Ans: Hibernate Query Language is designed for data management using Hibernate technology. It is completely object oriented and hence has notions like inheritance, polymorphism and abstraction. The queries are case-sensitive. This has an exception for Java classes and properties. The query operations are through objects. HQL acts as a bridge between Objects and RDBMS.

Q14. Name Hibernate’s three object states.

Ans: Detached, Transient, and Persistent.
This is a skills question, which makes sure you’ve spent enough time with the program to know its ins and outs.

Q15. Explain the advantages and disadvantages of detached objects.

Ans: Advantages:

  • Detached objects passing can be done across layers upto the presentation layer without using Data Transfer Objects.
  • At the time of using long transactions by the user which needs long think-time, it is suggested to split these transactions into some transactions. The detached objects get modified apart from the transaction scope which then can be re-attached to a new transaction.
  • The usage of detached objects are cumbersome and cryptic. It is suggested not to be cluttered with the session, if possible.
  • It is recommended to use DataTransferObjects and DomainObjects that is used to maintain separation between the user interfaces and the Service.
Topics:Hibernate Interview Questions and Answers For ExpeInformation Technologies (IT)



Top Courses in Python

Top Courses in Python

We help you to choose the right Python career Path at myTectra. Here are the top courses in Python one can select. Learn More →

aathirai cut mango pickle