Hibernate MCQ Test

Random Hibernate MCQs with answers: architecture, lazy loading and proxies, LazyInitializationException, the N+1 problem, caching, batch processing, useful annotations and best practices.

  • 20 random questions
  • 20 minutes
  • 21 in the question bank

No sign-up needed. Answers and explanations are shown at the end.

About this test

Hibernate interview questions usually go beyond annotations: lazy loading and LazyInitializationException, the N+1 select problem, first- and second-level cache, and batch processing. This test covers them.

Take the JPA test first if you are still new to entities and relationships.

Each attempt picks new questions at random from the question bank. You can go back and change answers until you finish or the timer runs out. At the end you see your score, the right answer and a short explanation for every question, and the lessons to revise for the ones you missed.

Sample questions with answers

1. Hibernate's relationship to JPA is…

  1. They are unrelated
  2. Hibernate implements JPA and adds extra features
  3. JPA implements Hibernate
Show answer

B. Hibernate implements JPA and adds extra features — Session extends EntityManager in Hibernate 6.

2. What causes LazyInitializationException?

  1. Touching a lazy association after the Session closed
  2. An EAGER relationship
  3. Too many queries
Show answer

A. Touching a lazy association after the Session closed — Load what you need inside the transaction.

3. Loading 5 authors then their lazy books one by one runs how many queries?

  1. 5
  2. 6
  3. 1
Show answer

B. 6 — 1 for authors + 1 per author.

4. Which cache is always on?

  1. The second-level cache
  2. The first-level (Session) cache
  3. The query cache
Show answer

B. The first-level (Session) cache — L2 and query caches are opt-in.

5. Which setting enables JDBC batching?

  1. hibernate.show_sql
  2. hibernate.cache.use_query_cache
  3. hibernate.jdbc.batch_size
Show answer

C. hibernate.jdbc.batch_size — Statements are sent in groups.

6. What does @SoftDelete change?

  1. Rows are moved to another table
  2. em.remove becomes an UPDATE setting a deleted flag, and queries skip deleted rows
  3. Nothing
Show answer

B. em.remove becomes an UPDATE setting a deleted flag, and queries skip deleted rows — Available in Hibernate 6.4+.

7. Which property should be false in Spring Boot?

  1. spring.jpa.show-sql
  2. spring.jpa.open-in-view
  3. spring.datasource.url
Show answer

B. spring.jpa.open-in-view — Open-in-view hides lazy loading in the web layer.