What are some common CrudRepository methods?

CrudRepository provides a small, ready-made set of methods that cover the standard create, read, update, and delete operations on an entity, so implementers don't need to hand-write basic persistence code.

Key Points

Example

A simple UserRepository extending CrudRepository<User, Long> immediately gains the ability to save a new user, look one up by ID, list all users, and delete a user, all without writing any SQL or implementation code.

public interface UserRepository extends CrudRepository<User, Long> {
}

// Usage
User saved = userRepository.save(new User("Alice"));
Optional<User> found = userRepository.findById(saved.getId());
Iterable<User> all = userRepository.findAll();
userRepository.deleteById(saved.getId());
long total = userRepository.count();

Interview Tip

A concise interview answer is

CrudRepository gives me save() for insert/update, findById() returning an Optional, findAll() to list everything, deleteById() to remove a record, and count()/existsById() for quick checks -- all without writing any implementation, just by extending the interface.

Last updated: 11 November 2026

Previous question: What is pagination, and how do you implement it in Spring Data?

Next question: What is the difference between delete() and deleteInBatch()?

More Spring Data JPA interview questions

All Spring Data JPA questions