chapter fourteen

14 Implementing data persistence with Spring Data

 

This chapter covers

  • How Spring Data works
  • Defining Spring Data repositories
  • Using Spring Data JDBC to implement a Spring app’s persistence layer

Most applications need to work with data. They store data, read it, change it, and sometimes delete it. In Spring apps, this part of the application is usually called the persistence layer. It is the part of the app that talks to the database.

Let’s now discuss Spring Data, a Spring project that helps you implement the persistence layer with less code. Instead of writing repository classes yourself, you declare repository interfaces, and Spring provides the implementations at runtime. This means you can create, read, update, and delete data without writing all the usual database access code by hand.

As you already know, an application framework’s essential role is providing out-of-the-box capabilities that you can directly plug into apps. Frameworks help us save time and make app design easier to understand.

Further, you’ll learn to create the app’s repositories by declaring interfaces, which is a different way to implement an app’s data persistence layer. You’ll let the framework provide implementations for these interfaces. You’ll literally enable your app to work with a database without implementing the repository yourself and with minimum effort!

14.1 What Spring Data is

14.2 How Spring Data works

14.3 Using Spring Data JDBC

14.4 Questions

14.5 Summary