Home/Interview Prep/Hibernate & JPA

Hibernate & JPA Interview Questions

The persistence context, entity lifecycle, mappings and relationships, fetching strategies and N+1, JPQL and Criteria, transactions and locking, caching — weighted toward what actually goes wrong in production.

Persistence ContextN+1MappingsTransactionsCachingAria-powered explanations
0 / 100 answered
0%
7 Easy49 Medium44 Hard

Showing 120 of 100

#1What is the difference between JPA and Hibernate?

Easy
Fundamentals

#2What is an entity and what does JPA require of one?

Easy
Fundamentals

#3What are the entity lifecycle states?

Medium
Fundamentals

#4What is the difference between persist, merge, save and saveOrUpdate?

Medium
Fundamentals

#5What identifier generation strategies exist and which should you use?

Hard
Fundamentals

#6What is the difference between @Entity and @Embeddable?

Medium
Fundamentals

#7What are the inheritance mapping strategies and what are their trade-offs?

Hard
Fundamentals

#8What is a DTO and why should you not return entities from an API?

Medium
Fundamentals

#9What is the difference between a Spring Data repository and an EntityManager?

Medium
Fundamentals

#10What does @Transactional actually do, and what are its common pitfalls?

Hard
Fundamentals

#11What is the difference between JPA and JDBC, and when would you use raw JDBC?

Medium
Fundamentals

#12What is the object-relational impedance mismatch?

Hard
Fundamentals

#13What is the persistence context and what does it do for you?

Medium
Persistence Context

#14What is flushing and when does it happen?

Hard
Persistence Context

#15What causes LazyInitializationException and how do you fix it properly?

Medium
Persistence Context

#16What is Open Session In View and why is it controversial?

Hard
Persistence Context

#17What is dirty checking and what are its costs?

Hard
Persistence Context

#18What is the difference between find, getReference and a query?

Medium
Persistence Context

#19How do you handle batch processing without exhausting memory?

Hard
Persistence Context

#20What does cascade do and which cascade types are dangerous?

Medium
Persistence Context

Showing 120 of 100

Ask Aria about Hibernate & JPA

Sign in to chat with Aria

All 100 Hibernate & JPA questions at a glance
  1. What is the difference between JPA and Hibernate?(Easy)
  2. What is an entity and what does JPA require of one?(Easy)
  3. What are the entity lifecycle states?(Medium)
  4. What is the difference between persist, merge, save and saveOrUpdate?(Medium)
  5. What identifier generation strategies exist and which should you use?(Hard)
  6. What is the difference between @Entity and @Embeddable?(Medium)
  7. What are the inheritance mapping strategies and what are their trade-offs?(Hard)
  8. What is a DTO and why should you not return entities from an API?(Medium)
  9. What is the difference between a Spring Data repository and an EntityManager?(Medium)
  10. What does @Transactional actually do, and what are its common pitfalls?(Hard)
  11. What is the difference between JPA and JDBC, and when would you use raw JDBC?(Medium)
  12. What is the object-relational impedance mismatch?(Hard)
  13. What is the persistence context and what does it do for you?(Medium)
  14. What is flushing and when does it happen?(Hard)
  15. What causes LazyInitializationException and how do you fix it properly?(Medium)
  16. What is Open Session In View and why is it controversial?(Hard)
  17. What is dirty checking and what are its costs?(Hard)
  18. What is the difference between find, getReference and a query?(Medium)
  19. How do you handle batch processing without exhausting memory?(Hard)
  20. What does cascade do and which cascade types are dangerous?(Medium)
  21. Why can equals and hashCode be problematic for entities?(Hard)
  22. What is the difference between the first-level and second-level cache?(Medium)
  23. What happens if you modify an entity outside a transaction?(Medium)
  24. What is the N+1 problem and how do you detect it?(Medium)
  25. What does mappedBy mean and which side owns a relationship?(Medium)
  26. Why is a unidirectional @OneToMany without a join column inefficient?(Hard)
  27. How should you map a @ManyToMany relationship?(Medium)
  28. What is the difference between @OneToOne with a shared primary key and with a foreign key?(Hard)
  29. When would you use @ElementCollection?(Medium)
  30. How do you map an enum, and why is ORDINAL dangerous?(Medium)
  31. What is an AttributeConverter and when is one useful?(Medium)
  32. How do you map a composite primary key?(Hard)
  33. What is the difference between List, Set and Map for a collection mapping?(Hard)
  34. How do you map a JSON column?(Medium)
  35. What is @MappedSuperclass and how does it differ from @Entity inheritance?(Medium)
  36. How do you handle auditing fields like createdAt and updatedBy?(Medium)
  37. What is the difference between @Column(nullable = false) and @NotNull?(Easy)
  38. Should you use ddl-auto in production?(Medium)
  39. What are the default fetch types and why do they matter?(Medium)
  40. What is JOIN FETCH and how does it differ from a plain join?(Hard)
  41. What is an EntityGraph and when is it better than JOIN FETCH?(Hard)
  42. What is @BatchSize and how does it help with N+1?(Hard)
  43. What is a DTO projection and why is it often the best answer?(Medium)
  44. Why does pagination with a fetch join produce a warning?(Hard)
  45. What is the Cartesian product problem when fetching multiple collections?(Hard)
  46. What is bytecode enhancement and what does it enable?(Hard)
  47. How do you decide between eager fetching everything and querying per use case?(Medium)
  48. What is the difference between fetch and load strategies in a query versus a mapping?(Medium)
  49. How do you fetch a paginated list with its associations efficiently?(Hard)
  50. Why might a query return duplicate entities and how do you fix it?(Medium)
  51. What is the read-only optimisation and why should you use it?(Medium)
  52. How do you diagnose which queries Hibernate is actually issuing?(Medium)
  53. What is JPQL and how does it differ from SQL?(Easy)
  54. When would you use the Criteria API?(Medium)
  55. How do you prevent SQL injection with JPA?(Medium)
  56. What is a native query and what do you lose by using one?(Medium)
  57. How do bulk update and delete queries interact with the persistence context?(Hard)
  58. What is the difference between getSingleResult, getResultList and Spring Data return types?(Medium)
  59. How does pagination work in Spring Data and what is the count query cost?(Medium)
  60. What are named queries and why use them?(Easy)
  61. How do you query across a polymorphic entity hierarchy?(Hard)
  62. What is the query cache and when is it worth enabling?(Hard)
  63. How do you handle a query that needs database-specific features?(Medium)
  64. What is the difference between a Spring Data derived query and @Query?(Medium)
  65. What are the transaction isolation levels and what problems does each prevent?(Hard)
  66. What is optimistic locking and how does @Version work?(Medium)
  67. When would you use pessimistic locking instead?(Hard)
  68. What are the transaction propagation types and when do they matter?(Hard)
  69. What happens if an exception is thrown inside a transaction?(Hard)
  70. How long should a transaction be, and what are the costs of a long one?(Medium)
  71. What is the lost update problem and how do you prevent it?(Medium)
  72. What is the difference between OPTIMISTIC and OPTIMISTIC_FORCE_INCREMENT?(Hard)
  73. How do you handle transactions across multiple services or databases?(Hard)
  74. What is a connection pool and how do you size one?(Hard)
  75. What is the difference between flush and commit?(Medium)
  76. How do you test transactional code?(Medium)
  77. When should you enable the second-level cache?(Hard)
  78. What are the second-level cache concurrency strategies?(Hard)
  79. How do collections interact with the second-level cache?(Hard)
  80. What cache invalidation problems does Hibernate not solve for you?(Hard)
  81. What is the difference between caching in Hibernate and caching in the application?(Medium)
  82. How do you verify that caching is actually helping?(Medium)
  83. What is a cache region and why does it matter?(Medium)
  84. Should you cache at the entity level or the query level?(Hard)
  85. What are the most common Hibernate performance problems in production?(Medium)
  86. How do you enable JDBC batching and why is it often not working?(Hard)
  87. Why might Hibernate issue an update you did not ask for?(Hard)
  88. What is @DynamicUpdate and when is it worth using?(Hard)
  89. How do you handle a very large result set without exhausting memory?(Hard)
  90. What is the impact of Open Session In View on the connection pool?(Hard)
  91. How do you find which entity or query is causing a slow endpoint?(Medium)
  92. What is the difference between StatelessSession and a normal Session?(Hard)
  93. Why is it a problem to put a network call inside a transaction?(Medium)
  94. What indexes does an ORM not create for you, and why does it matter?(Medium)
  95. When is an ORM the wrong tool?(Medium)
  96. What is the difference between hibernate.hbm2ddl.auto values?(Easy)
  97. How do you migrate a schema safely with an application running?(Hard)
  98. What is the outbox pattern and why does it come up with JPA?(Hard)
  99. How would you performance-tune an existing Hibernate application?(Hard)
  100. What would you tell someone using Hibernate for the first time?(Easy)