Top 3 Jpa Interview Questions
Browse 3 real-world technical and behavioral interview questions about Jpa. Review scenarios, edge cases, and architectural best practices.
Nobody called save, but the UPDATE still went to the database. Explain how that happened.
Hibernate dirty checking tracks a managed JPA entity through the persistence context. At flush the provider compares the entity against its loaded snapshot and writes an UPDATE for whatever differs, so mutating a managed object inside a transaction is itself the instruction to persist. Use this spring data jpa answer to show the decision, trade-off, and evidence rather than a memorised definition.
This endpoint logs one query per row. Why are you seeing N+1 queries, and how do you fix them?
You get N+1 when one query loads N rows and something later dereferences a lazy association on each of them, firing a select apiece. Fix it per call site with join fetch, an entity graph, or batch fetching - not by changing mappings to EAGER.
You pass a thousand new entities to saveAll and the database sees a thousand separate inserts. How do you get them batched?
Spring Data JPA saveAll batching needs a Hibernate batch size, statements for the same table kept adjacent, and an identifier strategy that does not force a round trip per row. IDENTITY generation silently prevents insert batching, because Hibernate has to execute each insert to learn the key.