liveBook · Manning

Spring Data

As explained in Spring Start Here, Second Edition

Spring Data is a family of Spring projects that simplifies access to data stores through consistent repository-based abstractions.

A persistence layer stores, reads, changes, and deletes an application’s data. Spring Data simplifies this work by providing common repository abstractions over different persistence technologies. Instead of implementing every repository class yourself, you declare interfaces and let Spring provide implementations at runtime. section 14.0 section 14.1

Figure 14.1 The Java ecosystem offers many various persistence technologies like Hibernate, JDBC, MongoDB, or others. Each technology has its own abstractions and class design. Spring Data offers a common abstraction layer over all these persistence technologies to simplify the use of multiple persistence technologies.

Spring Data sits between the application and persistence technologies, offering a common abstraction over their different APIs. section 14.1

Choose a Spring Data module for the technology your application uses: for example, Spring Data JDBC for JDBC or Spring Data MongoDB for MongoDB. The common approach reduces the amount of repository code you need to write, even though the underlying technologies differ. section 14.5 section 14.1

Repository interfaces can extend Spring Data contracts to inherit operations:

  • Repository defines no persistence operations itself. section 14.5
  • CrudRepository provides basic create, read, update, and delete operations. section 14.5
  • PagingAndSortingRepository adds pagination and sorting support. section 14.5

A repository can also declare custom operations. Use @Query to specify a query explicitly, or let Spring Data derive one from a method name that follows its naming rules. An invalid derived name causes startup to fail. For complex operations, @Query can be easier to maintain than a long derived name. Operations that change data, such as INSERT, UPDATE, or DELETE, must be annotated with @Modifying. section 14.5

Validating data in an automated test app

An automated testing application can use Spring Data to connect to databases and validate data as part of its test scenarios. It can combine this with other Spring capabilities, such as managing application objects or calling external APIs. section 1.3.2

How Spring Start Here, Second Edition covers it

How deep it goes
Explains repository contracts, module selection, query derivation, and annotations, without detailing repository implementation internals.
Examples
Uses database validation in an automated testing application and contrasts JDBC and MongoDB modules.
What it assumes
Builds on prior JDBC experience without requiring knowledge of every persistence technology.
What you can do after
Apply Spring Data by selecting a module, declaring repository interfaces, and choosing derived or explicit queries.
How it connects
Connects repository abstractions with JDBC, JPA, MongoDB, and CRUD operations.

Also explained in

Compare how 2 books explain Spring Data →

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.