Spring Data JDBC
Working with a relational database without a heavy ORM
Spring Data JDBC helps store Java objects in a relational database without forcing you to write typical data-access code by hand every time. It provides repositories, entity mapping, query support, and other familiar Spring Data features, while keeping the programming model much closer to SQL and JDBC than a full ORM does.
In this section, we will focus on describing application data, saving and reading it through repositories, writing the queries we need, and modeling related data correctly as aggregates. SQL and the table structure remain an important part of understanding the application.
What is inside this section
- Spring Data JDBC Basics. We will examine the library's overall model and where it sits between plain JDBC code and more complex persistence tools.
- Repositories. We will see how Spring creates an implementation of a repository interface and separates data access from the rest of the application.
- CrudRepository. We will learn the ready-made operations for saving, finding, checking the existence of, and deleting entities.
- Entity Mapping. We will connect a Java class to a database table, identifier, and columns.
- Queries. We will learn to retrieve data through repository methods whose names describe the selection condition.
- Custom Queries. We will switch to explicit SQL when a method name is no longer enough.
- Relationships and Aggregates. We will examine how Spring Data JDBC views related objects and where the boundaries of a persisted whole are drawn.
- Auditing. We will add automatic population of creation and modification times.
The topics move from a simple repository to the data model and more precise control over SQL. After this section, you will understand how to build a small relational data-access layer with Spring Data JDBC without losing the connection between Java code and the actual table schema.