This chapter presents some fundamental mapping options and explains how to map entity classes to SQL tables. This is essential knowledge for structuring classes in an application, no matter whether you work with Hibernate, Spring Data JPA, or some other persistence framework that implement the JPA specification. We’ll demonstrate and analyze how you can handle database identity and primary keys, and how you can use various other metadata settings to customize how Hibernate or Spring Data JPA using Hibernate as a persistence provider will load and store instances of your domain model classes.
Spring Data JPA, as a data access abstraction, sits on top of a JPA provider (such as Hibernate) and will significantly reduce the boilerplate code required to interact with the database. That is why, once the mapping of persistent classes is made, it can be used both from Hibernate and from Spring Data JPA. Our examples will demonstrate this, and all our mapping examples will use JPA annotations.