What is the @Entity annotation and JPA basics?

Answer

JPA (Java Persistence API) is the standard specification for ORM (Object-Relational Mapping) in Java. Hibernate is the most common implementation. Core annotations: @Entity — marks a class as a JPA entity (maps to a DB table); @Table(name = "users") — specify table name (optional if same as class name); @Id — marks the primary key field; @GeneratedValue(strategy = GenerationType.IDENTITY) — auto-generate primary key (IDENTITY uses DB auto-increment, SEQUENCE uses DB sequence, AUTO lets JPA decide); @Column(name = "email_address", nullable = false, unique = true, length = 255) — map to a column with constraints; @Transient — field NOT persisted to DB; @Enumerated(EnumType.STRING) — store enum as string (not ordinal). Example entity: @Entity @Table(name = "users") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false) private String name; @Column(unique = true, nullable = false) private String email; @Enumerated(EnumType.STRING) private UserStatus status = UserStatus.ACTIVE; @CreatedDate @Column(updatable = false) private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime updatedAt; }. Relationships: @OneToOne, @OneToMany, @ManyToOne, @ManyToMany. Cascade: @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) — operations propagate to children. Fetch types: LAZY (default for @OneToMany, @ManyToMany) vs EAGER (default for @ManyToOne, @OneToOne).