Hibernate Interview Questions


Hibernate interview questions are asked to the students because it is a widely used ORM tool. The important list of top hibernate interview questions and answers for freshers and Experience are given below.


1) What is hibernate?


Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.

2.What is ORM ?


ORM stands for object/relational mapping. ORM is the automated persistence of objects in a Java application to the tables in a relational database.

2.What does ORM consists of ?


An ORM solution consists of the followig four pieces:

  • API for performing basic CRUD operations
  • API to express queries refering to classes
  • Facilities to specify metadata
  • Optimization facilities : dirty checking,lazy associations fetching

3.What are the ORM levels ?


The ORM levels are:

  • Pure relational (stored procedure.)
  • Light objects mapping (JDBC)
  • Medium object mapping
  • Full object Mapping (composition,inheritance, polymorphism, persistence by reachability)

4.Why do you need ORM tools like hibernate?


The main advantage of ORM like hibernate is that it shields developers from messy SQL. Apart from this, ORM provides following benefits:

  • Improved productivity
    • High-level object-oriented API
    • Less Java code to write
    • No SQL to write
  • Improved performance
    • Sophisticated caching
    • Lazy loading
    • Eager loading
  • Improved maintainability
    • A lot less code to write
  • Improved portability
    • ORM framework generates database-specific SQL for you

6. What are the core interfaces of Hibernate?


The core interfaces of Hibernate framework are:

  • Configuration
  • SessionFactory
  • Session
  • Query
  • Criteria
  • Transaction

7 .What are the most common methods of Hibernate configuration?


The most common methods of Hibernate configuration are:

  • Programmatic configuration
  • XML configuration (hibernate.cfg.xml)

8. Is SessionFactory a thread-safe object?


Yes, SessionFactory is a thread-safe object, many threads can access it simultaneously.

9. What role does the SessionFactory interface play in Hibernate?


The application obtains Session instances from a SessionFactory. There is typically a single SessionFactory for the whole applicationå¹¼reated during application 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();

10. Is Session a thread-safe object?


No, Session is not a thread-safe object, many threads can't access it simultaneously. In other words, you cannot share it between threads.,