Spring Data JPA
The JPA-flavoured repository module: JpaRepository, derived queries, @Query with JPQL or native SQL, entity graphs, locking, Specifications and stored procedures. Most Java backend interviews spend real time here, because most Java backends persist through it.
part ofSpring Frameworkoverview, primer and where to startread it →on this pageshowhide
explore
- JpaRepository Abstractions5 questions
- JPA Derived Query Methods5 questions
- @Query JPQL, Native & @Modifying5 questions
- @EntityGraph Fetch Tuning5 questions
- @Lock & Optimistic/Pessimistic Locking5 questions
- Specifications & Criteria5 questions
- @Procedure, Query Hints & Streaming5 questions
questions
page 2 of 2Design a memory-safe path to export millions of rows via a Spring Data JPA repository. Which mechanisms do you combine and why?
basics
~10 sReturn a Stream<T>, consume it inside a read-only transaction, and close it with try-with-resources. Add @QueryHints for fetch size and readOnly, and periodically detach/clear entities so the persistence context and heap stay bounded.
How does the SpEL expression #{#entityName} work in a @Query, and why is it useful?
basics
~20 sSpring Data lets you embed SpEL in a @Query using #{...}. The built-in #entityName variable resolves to the managed entity's name at runtime, so you can write generic base-repository queries like SELECT e FROM #{#entityName} e that work for any entity subtype.
When should you extend JpaRepository versus compose custom repository fragments?
basics
~20 sExtend JpaRepository for standard CRUD, derived queries and @Query methods. Add a custom fragment (an interface plus an Impl) when a method needs hand-written logic — EntityManager, Criteria API, QueryDSL — that derived queries and @Query can't express. Compose narrow fragments to restrict the exposed API.
When would you choose Specifications over QueryDSL, Query-by-Example, or @Query, and what are their trade-offs at scale?
basics
~20 sUse Specifications for dynamic, reusable, composable filters built at runtime with type-safe Criteria. Prefer @Query for fixed complex queries, Query-by-Example for simple probe matching, and QueryDSL when you want a fluent DSL and heavy compile-time safety.
How do you map a stored procedure that returns a result set (REF_CURSOR) or multiple OUT parameters in Spring Data JPA?
basics
~10 sDeclare a JPA @NamedStoredProcedureQuery on an entity with @StoredProcedureParameter entries — use mode REF_CURSOR for a returned result set or several OUT parameters — then reference it from the repository via @Procedure(name = "...").
showing 31–35 of 35