Entity Mapping with JPA Annotations
Define @Entity, @Table, @Id, @GeneratedValue, @Column, and @Embedded for clean entity design.
What Is JPA Entity Mapping?
JPA (Jakarta Persistence API) maps Java classes to database tables using annotations. Hibernate is the most common JPA provider. No SQL DDL required — JPA generates schemas from annotations.
@Entity and @Table
@Entity marks a class as a JPA entity. @Table customizes the table name, schema, and unique constraints. Every entity must have a no-arg constructor (can be protected).
@Entity
@Table(name = "users", uniqueConstraints = @UniqueConstraint(columnNames = "email"))
public class User {
// ...
protected User() {} // required by JPA
}All lessons in this course
- Entity Mapping with JPA Annotations
- Spring Data Repositories and Query Methods
- One-to-Many and Many-to-Many Relationships
- Pagination, Sorting, and Projections