3 Working with data

 

This chapter covers

  • Using Spring’s JdbcTemplate
  • Creating Spring Data JDBC repositories
  • Declaring JPA repositories with Spring Data

Most applications offer more than just a pretty face. Although the user interface may provide interaction with an application, it’s the data it presents and stores that separates applications from static websites.

In the Taco Cloud application, you need to be able to maintain information about ingredients, tacos, and orders. Without a database to store this information, the application wouldn’t be able to progress much further than what you developed in chapter 2.

In this chapter, you’re going to add data persistence to the Taco Cloud application. You’ll start by using Spring support for JDBC (Java Database Connectivity) to eliminate boilerplate code. Then you’ll rework the data repositories to work with JPA (Java Persistence API), eliminating even more code.

3.1 Reading and writing data with JDBC

For decades, relational databases and SQL have enjoyed their position as the leading choice for data persistence. Even though many alternative database types have emerged in recent years, the relational database is still a top choice for a general-purpose data store and will not likely be usurped from its position any time soon.

3.1.1 Adapting the domain for persistence

3.1.2 Working with JdbcTemplate

3.1.3 Defining a schema and preloading data

3.1.4 Inserting data

3.2 Working with Spring Data JDBC

3.2.1 Adding Spring Data JDBC to the build

3.2.2 Defining repository interfaces

3.2.3 Annotating the domain for persistence

3.2.4 Preloading data with CommandLineRunner

3.3 Persisting data with Spring Data JPA

3.3.1 Adding Spring Data JPA to the project

3.3.2 Annotating the domain as entities