liveBook · Manning

Custom repository operation

As explained in Spring Start Here, Second Edition

A custom repository operation is a repository method that performs a data-access action beyond the repository's inherited standard operations.

A custom repository operation adds a data-access action beyond the standard operations inherited from a Spring Data repository contract. section 14.3

In Spring Data JDBC, repository methods can:

  • Use a method name such as findAccountsByName to retrieve matching accounts. section 14.3
  • Use @Query to specify SQL explicitly, or combine it with @Modifying for an update. section 14.3

Account lookup

An AccountRepository extending CrudRepository can add findAccountsByName(String name). In a wallet application, a service can use this operation to find accounts while implementing a money transfer. section 14.3

Listing 14.5 Adding a repository operation to get all the accounts with a specified name
public interface AccountRepository 
  extends CrudRepository<Account, Long> {
 
  List<Account> findAccountsByName(String name);
  
}

See the repository declaration for a derived-name operation that finds accounts by name. section 14.3

How Spring Start Here, Second Edition covers it

How deep it goes
Demonstrates derived-name lookups, explicit SQL, and modifying operations through repository declarations.
Examples
Uses a wallet account lookup and an SQL update to change an account balance.
What you can do after
Apply it via Spring Data JDBC by defining derived-name or @Query methods, including @Modifying updates.
How it connects
Connects custom methods to Spring Data repositories, CrudRepository, SQL queries, and modifying operations.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring Start Here, Second Edition. The section links point to the parts of the book it draws on.