Search⌘ K

Defining an Entity

Explore how to define an entity class in Spring Data JPA by using core annotations such as @Entity, @Table, @Id, and @GeneratedValue. Understand how these annotations map Java objects to database tables and columns, and how Spring Boot creates tables automatically, simplifying database integration.

JPA dependency

To use Spring Data JPA, we will add the starter JPA dependency to the pom.xml file of the tennis-player project as follows:

XML
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

When the pom.xml file is saved, we can see the JPA API in the Maven Dependencies folder. This API defines a lot of different annotations like @Entity, @Column, @Table, etc. Hibernate is an implementation of the JPA API which automatically gets configured in our application. The hibernate-core jar can be seen in the Maven Dependencies folder.

We will take the tennis player database example to ...