Key Concepts

Review core concepts you need to learn to master this subject

Spring Java Data Model

A data model is the set of objects that represents the concepts in your problem domain, whose data you will want to ultimately store in a database.

For example in a music playlist application, the data model would consist of artists, albums, and tracks, and the possible relations between them.

Add a Database with JPA
Lesson 1 of 2
  1. 1
    Spring Data JPA is a library for Spring that helps to integrate a database into your REST API. In this lesson, we will create an application that will help a botanist keep track of their inventory…
  2. 2
    To connect to an embedded H2 database using Spring Data JPA, we’ll need to update your application’s properties. Spring uses a properties file to store information that your application depen…
  3. 3
    As mentioned earlier, Spring Data JPA is an abstraction layer that allows us to interact with objects in your code rather than write SQL queries. These objects, in this context, are referred to …
  4. 4
    Now that we have learned how data models are defined, the next step is to determine how to use the model to interact with the database. Spring Data JPA uses repositories to accomplish this. A rep…
  5. 5
    The repository interfaces provided by Spring Data JPA, such as CrudRepository, are very powerful for managing data without having to write too much code. However, they are not of much use without a…
  6. 6
    Now that you can communicate between your controller and your data access layer, you’ve bridged the gap between an end user of your API and the database. One of the fastest ways to test this funct…
  7. 7
    Rather than get all items, our API users may want to find a specific entity in the database. For this kind of request, we can use CrudRepository methods like .findById(Integer id). Continuing the …
  8. 8
    Conventionally, a GET request is used when you wish to GET information from the database. Similarly, a POST request is used when we wish to create new information in the database. With Spring Data…
  9. 9
    The .save method from the CrudRepository interface can be used both for creating new entries in the database as well as updating existing entries. A common flow is to fetch an entry from the datab…
  10. 10
    So far, you have: - Used a POST endpoint to Create a database entry - Used a GET endpoint to Read database entries - Used a PUT endpoint to Update a database entry Sounds like you’re j…
  11. 11
    Congratulations! You’ve completed a CRUD application end-to-end with Spring Boot and Spring Data JPA. Your application can: - Create plants in the database by making POST requests and …

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo