©2018 by javanotes.

Search
  • Madhu Reddy

Hibernate Interview Questions

Updated: Oct 20, 2018

1)What Is ORM?


ORM Stands for Object Relational Mapping(ORM). It is used for mapping model objects to the Relational Database Tables.

2) What is Hibernate?

Hibernate is a Java based ORM Framework. Hibernate Maps the Java Model Classes to the Relational Database tables. Hibernate Eliminates all the boiler plate code that comes with the JDBC. so the developer can focus on the business logic rather than spending time on database connections. 3)What are the advantages of using Hibernate?

  1. Hibernate is an open source framework from Red Hat. so it is easy to learn hibernate as we can find plenty of resources online.

  2. Hibernate eliminates all the boiler plate code that comes with JDBC so it makes easy for the developer to just concentrate on business logic.

  3. Hibernate has the support for both JPA Annotations and XML(Used for Mapping the Model Classes to the Database Tables).

  4. Hibernate supports cacheing( First Level, Second Level, Query Cache). This improves the Application Performance.

  5. Hibernate provides support for native sql queries.On top of that it also provides HQL( Hibernate Query Language) which is purely Object Oriented.

4) Advantages of Hibernate over JDBC??

  1. Hibernate eliminates all the boiler plate code that comes with JDBC so it makes easy for the developer to just concentrate on business logic. B)

  2. Hibernate has the support for both JPA Annotations and XML(Used for Mapping the Model Classes to the Database Tables).

  3. Hibernate supports cacheing( First Level, Second Level, Query Cache). This improves the Application Performance.

  4. Hibernate provides support for native sql queries.On top of that it also provides HQL( Hibernate Query Language) which is purely Object Oriented.

  5. Hibernate Provides support for Transaction Management.

Hence Hibernate is one of the most used ORM Framework. 5)What are some of the Important Interfaces and Objects in Hibernate?

  1. Session Factory: Session Factory object is used for creating the Session objects. Session factory objects are created using singleton design pattern. so once instance of the session factory object will be used through out the application. Session factory object is immutable and Thread Safe. Session factory object contains the connection information, hibernate configuration information and Mapping files information.

  2. Session: Session Object is created using Session. Factory Object. Unlike Session factory object One Session Object will be created per client. Session object should be used carefully and it should only be created when its needed.It should be closed once it’s usage is done. Session object provides the methods to perform the CRUD operations.

  3. Transaction: It is an object used by the application to make the atomic units of work. Transaction is usually associated with a session object and it is instantiated by making a call to session.beginTransaction() .


6) Is session factory Thread safe??

Session factory object is immutable and is thread safe.

7) Is Hibernate session object Thread Safe??

Hibernate Session object is not thread safe. Every thread should get its own session instance and should be closed after used. 9) What are the different states of an Entity Bean??

  1. Transient: An Entity bean which is never associated with the session is said to be transient state.

A newly created Entity Bean is said to be in Transient state.B) Persistence : When an Entity bean is said to be attached with a session then it is said to be in Persistence state. Any changes made to this entity will be reflected in database.C) Detached: When an Entity Bean removed from a session it is said to be in detached state. Any changes made to Entity Bean in this state is not reflected in database.