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-memory database. To be able to use JPA and the H2 database, we have to add the following dependencies to the build.gradle
file:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database...