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.
Showing 1–20 of 100
#1What is the difference between JPA and Hibernate?
#2What is an entity and what does JPA require of one?
#3What are the entity lifecycle states?
#4What is the difference between persist, merge, save and saveOrUpdate?
#5What identifier generation strategies exist and which should you use?
#6What is the difference between @Entity and @Embeddable?
#7What are the inheritance mapping strategies and what are their trade-offs?
#8What is a DTO and why should you not return entities from an API?
#9What is the difference between a Spring Data repository and an EntityManager?
#10What does @Transactional actually do, and what are its common pitfalls?
#11What is the difference between JPA and JDBC, and when would you use raw JDBC?
#12What is the object-relational impedance mismatch?
#13What is the persistence context and what does it do for you?
#14What is flushing and when does it happen?
#15What causes LazyInitializationException and how do you fix it properly?
#16What is Open Session In View and why is it controversial?
#17What is dirty checking and what are its costs?
#18What is the difference between find, getReference and a query?
#19How do you handle batch processing without exhausting memory?
#20What does cascade do and which cascade types are dangerous?
Showing 1–20 of 100
Ask Aria about Hibernate & JPA
Sign in to chat with Aria
All 100 Hibernate & JPA questions at a glance
- What is the difference between JPA and Hibernate?(Easy)
- What is an entity and what does JPA require of one?(Easy)
- What are the entity lifecycle states?(Medium)
- What is the difference between persist, merge, save and saveOrUpdate?(Medium)
- What identifier generation strategies exist and which should you use?(Hard)
- What is the difference between @Entity and @Embeddable?(Medium)
- What are the inheritance mapping strategies and what are their trade-offs?(Hard)
- What is a DTO and why should you not return entities from an API?(Medium)
- What is the difference between a Spring Data repository and an EntityManager?(Medium)
- What does @Transactional actually do, and what are its common pitfalls?(Hard)
- What is the difference between JPA and JDBC, and when would you use raw JDBC?(Medium)
- What is the object-relational impedance mismatch?(Hard)
- What is the persistence context and what does it do for you?(Medium)
- What is flushing and when does it happen?(Hard)
- What causes LazyInitializationException and how do you fix it properly?(Medium)
- What is Open Session In View and why is it controversial?(Hard)
- What is dirty checking and what are its costs?(Hard)
- What is the difference between find, getReference and a query?(Medium)
- How do you handle batch processing without exhausting memory?(Hard)
- What does cascade do and which cascade types are dangerous?(Medium)
- Why can equals and hashCode be problematic for entities?(Hard)
- What is the difference between the first-level and second-level cache?(Medium)
- What happens if you modify an entity outside a transaction?(Medium)
- What is the N+1 problem and how do you detect it?(Medium)
- What does mappedBy mean and which side owns a relationship?(Medium)
- Why is a unidirectional @OneToMany without a join column inefficient?(Hard)
- How should you map a @ManyToMany relationship?(Medium)
- What is the difference between @OneToOne with a shared primary key and with a foreign key?(Hard)
- When would you use @ElementCollection?(Medium)
- How do you map an enum, and why is ORDINAL dangerous?(Medium)
- What is an AttributeConverter and when is one useful?(Medium)
- How do you map a composite primary key?(Hard)
- What is the difference between List, Set and Map for a collection mapping?(Hard)
- How do you map a JSON column?(Medium)
- What is @MappedSuperclass and how does it differ from @Entity inheritance?(Medium)
- How do you handle auditing fields like createdAt and updatedBy?(Medium)
- What is the difference between @Column(nullable = false) and @NotNull?(Easy)
- Should you use ddl-auto in production?(Medium)
- What are the default fetch types and why do they matter?(Medium)
- What is JOIN FETCH and how does it differ from a plain join?(Hard)
- What is an EntityGraph and when is it better than JOIN FETCH?(Hard)
- What is @BatchSize and how does it help with N+1?(Hard)
- What is a DTO projection and why is it often the best answer?(Medium)
- Why does pagination with a fetch join produce a warning?(Hard)
- What is the Cartesian product problem when fetching multiple collections?(Hard)
- What is bytecode enhancement and what does it enable?(Hard)
- How do you decide between eager fetching everything and querying per use case?(Medium)
- What is the difference between fetch and load strategies in a query versus a mapping?(Medium)
- How do you fetch a paginated list with its associations efficiently?(Hard)
- Why might a query return duplicate entities and how do you fix it?(Medium)
- What is the read-only optimisation and why should you use it?(Medium)
- How do you diagnose which queries Hibernate is actually issuing?(Medium)
- What is JPQL and how does it differ from SQL?(Easy)
- When would you use the Criteria API?(Medium)
- How do you prevent SQL injection with JPA?(Medium)
- What is a native query and what do you lose by using one?(Medium)
- How do bulk update and delete queries interact with the persistence context?(Hard)
- What is the difference between getSingleResult, getResultList and Spring Data return types?(Medium)
- How does pagination work in Spring Data and what is the count query cost?(Medium)
- What are named queries and why use them?(Easy)
- How do you query across a polymorphic entity hierarchy?(Hard)
- What is the query cache and when is it worth enabling?(Hard)
- How do you handle a query that needs database-specific features?(Medium)
- What is the difference between a Spring Data derived query and @Query?(Medium)
- What are the transaction isolation levels and what problems does each prevent?(Hard)
- What is optimistic locking and how does @Version work?(Medium)
- When would you use pessimistic locking instead?(Hard)
- What are the transaction propagation types and when do they matter?(Hard)
- What happens if an exception is thrown inside a transaction?(Hard)
- How long should a transaction be, and what are the costs of a long one?(Medium)
- What is the lost update problem and how do you prevent it?(Medium)
- What is the difference between OPTIMISTIC and OPTIMISTIC_FORCE_INCREMENT?(Hard)
- How do you handle transactions across multiple services or databases?(Hard)
- What is a connection pool and how do you size one?(Hard)
- What is the difference between flush and commit?(Medium)
- How do you test transactional code?(Medium)
- When should you enable the second-level cache?(Hard)
- What are the second-level cache concurrency strategies?(Hard)
- How do collections interact with the second-level cache?(Hard)
- What cache invalidation problems does Hibernate not solve for you?(Hard)
- What is the difference between caching in Hibernate and caching in the application?(Medium)
- How do you verify that caching is actually helping?(Medium)
- What is a cache region and why does it matter?(Medium)
- Should you cache at the entity level or the query level?(Hard)
- What are the most common Hibernate performance problems in production?(Medium)
- How do you enable JDBC batching and why is it often not working?(Hard)
- Why might Hibernate issue an update you did not ask for?(Hard)
- What is @DynamicUpdate and when is it worth using?(Hard)
- How do you handle a very large result set without exhausting memory?(Hard)
- What is the impact of Open Session In View on the connection pool?(Hard)
- How do you find which entity or query is causing a slow endpoint?(Medium)
- What is the difference between StatelessSession and a normal Session?(Hard)
- Why is it a problem to put a network call inside a transaction?(Medium)
- What indexes does an ORM not create for you, and why does it matter?(Medium)
- When is an ORM the wrong tool?(Medium)
- What is the difference between hibernate.hbm2ddl.auto values?(Easy)
- How do you migrate a schema safely with an application running?(Hard)
- What is the outbox pattern and why does it come up with JPA?(Hard)
- How would you performance-tune an existing Hibernate application?(Hard)
- What would you tell someone using Hibernate for the first time?(Easy)