Creating the entity classes
An entity class is a simple Java class that is annotated with JPA's @Entity
annotation. Entity classes use the standard JavaBean naming convention and have proper getter and setter methods. The class fields have private visibility.
JPA creates a database table called by the name of the class when the application is initialized. If you want to use some other name for the database table, you can use the @Table
annotation in your entity class.
At the beginning of this chapter, we will use the H2 database (https://www.h2database.com/), which is embedded in our in-memory database. To be able to use JPA and the H2 database, we have to add the following dependencies to the pom.xml
file:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>...