Scrivio Interview library

Spring Data JPA

25 questions in 7 subtopics.

Repository interfaces

ConceptFoundations6 min read
Explain the Spring Data repository hierarchy (Repository, CrudRepository, ListCrudRepository, PagingAndSortingRepository, JpaRepository) and how a repository interface gets an implementation at runtime.
InternalsFoundations7 min read
How does SimpleJpaRepository.save() decide between persist and merge, and why can saving an entity with an assigned id cause an extra SELECT?
DebuggingIntermediate6 min read
A developer calls repository.deleteById(id) for 10,000 ids in a loop and it takes minutes. What SQL runs, and what are faster options?
DesignAdvanced7 min read
Should repositories be exposed directly to controllers or other modules? Describe the layering rules you would set for Spring Data repositories in a modular monolith.
DesignPrincipal6 min read
Your company is deciding whether new services should use Spring Data JPA, Spring Data JDBC, a SQL-first library such as jOOQ, or a mix. Frame the decision for a ten-year horizon, including skills, upgrade cost and vendor risk.

Derived query methods

CodingFoundations7 min read
What SQL would Spring Data JPA generate for List<User> findTop10ByStatusAndCreatedAtAfterOrderByCreatedAtDesc(Status s, Instant t), and what happens if you misspell a property name?
DebuggingFoundations6 min read
A derived method void deleteByStatus(Status s) on a JpaRepository fails with 'No EntityManager with actual transaction available for current thread' when called from a non-transactional service. Why, and what does it actually do when it works?
ConceptIntermediate7 min read
Explain existsBy, countBy and the projection return types of derived queries. How can you make an existence check efficient?
LeadershipPrincipal6 min read
Convenience features such as derived query methods let teams ship quickly but hide data access details. How would you balance delivery speed and long-term maintainability in data access across a large engineering organisation?

@Query

CodingFoundations6 min read
Write a @Query method with named parameters that finds orders by status and minimum total, and explain when the @Param annotation is needed.
CodingIntermediate7 min read
Write a paged native query with @Query in Spring Data JPA and explain why you may need countQuery. Mention any newer annotation for native queries.
ScenarioAdvanced7 min read
A large codebase has hundreds of @Query strings with duplicated filters and no tests. Schema changes break them only at runtime in some environments. What would you put in place?

Paging and sorting

ConceptFoundations6 min read
What is the difference between Page, Slice and List as return types for a paged repository method in Spring Data?
CodingIntermediate6 min read
Implement keyset (scrolling) pagination with Spring Data JPA's Window and ScrollPosition API for a feed of posts ordered by createdAt and id.
ScenarioAdvanced6 min read
A public endpoint accepts sort=anyProperty and size=anything, passed straight to Spring Data. What risks does this create and what guardrails would you add?
ScenarioPrincipal7 min read
Your data volumes grew a hundredfold over eight years, and paging and sorting choices that worked early (offset paging, sorting on any field, exact totals) now cause most of your slow queries. What would you change in standards and in existing systems?

Specifications and Querydsl

CodingFoundations6 min read
Write Spring Data JPA Specifications for 'status equals' and 'created after' and combine them in a repository call.
ScenarioIntermediate7 min read
Compare Spring Data Specifications and Querydsl for dynamic queries in a long-lived project. What would make you pick one over the other?
LeadershipAdvanced6 min read
Your platform depends heavily on a query library whose maintenance has slowed. How do you assess and manage the risk of a core data access dependency becoming unmaintained?

Auditing

CodingFoundations6 min read
Set up Spring Data JPA auditing so entities get createdAt, updatedAt and createdBy filled automatically.
DesignIntermediate7 min read
A regulator requires a complete change history for customer records: who changed what and when, for seven years. Compare Spring Data auditing, Hibernate Envers, database triggers and change data capture.
DesignAdvanced7 min read
Several services each implement auditing differently (Spring Data annotations, Envers, custom tables, logs). Design a consistent auditing approach for the organisation.

Custom repository implementations

CodingFoundations6 min read
Add a custom method with hand-written JPQL or Criteria code to a Spring Data repository. Show the interfaces, the implementation class name and how Spring finds it.
DesignIntermediate7 min read
How would you add a soft-delete or tenant filter behaviour to all repositories in a service? Compare a custom base repository class with Hibernate filters and other options.
LeadershipPrincipal6 min read
Spring Data repositories have shaped how a generation of Java developers think about data access. What long-term risks and benefits do you see in making them the default abstraction across a large organisation?