As we know, in the last couple of years, unstructured and non-relational databases (known as NoSQL) have become popular. With the Spring JPA, talking to relational databases became easy; so, how can we talk to non-relational databases? Spring developed a module called Spring Data to provide a common approach to talk to a wide variety of data stores.
As each persistence store has different ways to connect and retrieve/update data, Spring Data provides a common approach to accessing data from each different store.
The following are the features of Spring Data:
- Easy integration with multiple data stores, through various repositories. Spring Data provides generic interfaces for each data store in the form of repositories.
- The ability to parse and form queries based on repository method names provided the convention is followed. This reduces the amount of code to be written to fetch data.
- Basic auditing support, such as created by and updated by a user.
- Fully integrated with the Spring core module.
- Integrated with the Spring MVC to expose REpresentational State Transfer (REST) controllers through the Spring Data REST module.
The following is a small sample of the Spring Data repository. We don't need to implement this method to write a query and fetch an account by ID; it will be done by Spring Data internally:
public interface AccountRepository extends CrudRepository<Account, Long> {
Account findByAccountId(Long accountId);
}