Top-100 Hibernate Interview Questions

Hibernate interview questionsIt’s the 2nd part of Java interview questions series, the 1st one part is Core Java Interview Questions and 3rd part is Spring Interview Questions.

My plan is to collect all the most popular questions and answers, but as the 1st step, I decided to start with questions only.

When my list will be full, I’ll start to add answers step-by-step.

Today’s topic is “Java Hibernate Interview Questions”.

Why is it Hibernate? Because Spring and Hibernate Frameworks are gentleman’s set of Java developer.

According to my experience, almost 80% of interviewers want to ask you something about Hibernate.

That’s why It’s an important part of a preparation for an interview.

My Java Hibernate Interview Question List

Here I did the same as in the previous article – added filter and divided questions on the 3 levels: basic, medium and advanced.

I think if junior doesn’t know an answer to the advanced question – it’s ok, but he definitely should know answers to basic questions.

Senior developers should know all answers to these hibernate interview questions if he wants to get a good offer.

General and Architecture Questions

  • What are advantages of Hibernate?
  • What is ORM?
  • What is a difference between Hibernate and JDBC?
  • What is JPA?
  • What is a difference between Hibernate and JPA?
  • Explain Hibernate architecture
  • What’s general hibernate flow using RDBMS?
  • What is Hibernate validation framework?
  • What design patterns implemented in Hibernate?
  • What are the best practices could you recommend when you’re using Hibernate?

Configuration and Statistics

  • What are ways to configure Hibernate?
  • What is a purpose of dialect in the configuration?
  • How to use JNDI DataSource with Hibernate?
  • How to integrate Hibernate with a Spring Framework?
  • What is Hibernate mapping file?
  • What is a connection provider?
  • How to show Hibernate queries in the log?
  • How to get Hibernate statistics?
  • What is Envers API?
  • What is @Audited annotation?

Object Mapping

  • What are ways to map entity?
  • What are equals() and hashCode() overriding rules?
  • How to map entity using annotations?
  • What are requirements for Entity class?
  • What happens if Entity doesn’t have a default constructor?
  • Why Entity class can’t be final?
  • What are collections supported by Hibernate?
  • What is Bag collection and how can we use it?
  • What is a difference between sorted collection and ordered collection?
  • What types of inheritance mapping do you know in Hibernate?
  • What types of associations do you know?
  • How to a indicate that field should not be persisted?
  • How to make entity immutable using Hibernate?
  • How to map primary key?
  • What generation id strategies do you know?

Core Interfaces

  • What are main interfaces in Hibernate?
  • What is Hibernate Session?
  • Is session thread-safe?
  • What is a difference between openSession() and getCurrentSession()?
  • What is SessionFactory?
  • How to create SessionFactory?
  • Is SessionFactory thread-safe?
  • What is HibernateTemplate?
  • How many instances of Session and SessionFactory are usually created?

Object States

  • What hibernate object states do you know?
  • What is a detached object?
  • Can we reattach detached object and how to do it?
  • When object becomes detached?
  • What is a transient object?
  • What is a persistent object?

Data Manipulation

  • What is a cascade update?
  • What cascade types do you know?
  • What is a dirty checking mechanism?
  • What loading strategies do you know?
  • What is FetchType?
  • What is default FetchType for @OneToMany (@ManyToMany, @OneToOne)?
  • Which association types are eagerly loaded by default?
  • What is eager loading in Hibernate?
  • What is lazy loading in Hibernate?
  • What is a Hibernate Proxy and how is it connected with a lazy loading?
  • What is a lazy initialization?
  • What is a LazyInitializationException and how to avoid it?
  • What is the difference between get() and load()?
  • How to use session.merge() method?
  • What is a difference between merge() and update() methods?
  • What is a difference between methods save(), saveOrUpdate() and persist()?
  • What is a DetachedCriteria?
  • What is N+1 problem?
  • How can to use joins in Hibernate?
  • What is HSQL and what is its advantages?
  • How to execute stored procedures?
  • Is it possible to execute a native query? How to do that?
  • What is a Named Query?
  • What are benefits of Hibernate Criteria API?

Transaction Management

  • What is a transaction?
  • How does transaction management work in Hibernate?
  • What Hibernate transaction management types do you know?
  • What is transaction propagation?
  • What types of transaction propagation do you know?
  • What is a transaction isolation level?
  • What is a transaction factory?
  • What is FlushMode?
  • What types of locks do you know in Hibernate?
  • What is a difference between optimistic lock and pessimistic lock?
  • How optimistic lock works?
  • What are 2 ways how to use optimistic lock in Hibernate?
  • How pessimistic lock works?
  • How to use pessimistic lock in Hibernate?
  • What is session.lock() method?
  • How to rollback transaction?

Cache Management

  • How many cache levels do you know in Hibernate?
  • What cache strategies do you know?
  • What is the 1st level cache?
  • Is it possible to disable 1st level cache?
  • What is the 2nd level cache?
  • What different types of 2nd level cache?
  • What is a difference between 1st and 2nd levels of cache?
  • What is the 3rd level cache or query cache?
  • What types of shared cache mode do you know?
  • How to clear cache?

As I mentioned before I’ll add answers step-by-step.

I think this Hibernate interview questions would be useful for every Java programmer and you should definitely add this page to your bookmarks.

New interview questions and any suggestions are always welcome in comments.

Let’s collect the best question list together!

1 Star2 Stars3 Stars4 Stars5 Stars
Scroll Up