JPA
JPA
JPA Annotations
Annotation Purpose Example
@Entity Marks a class as a JPA entity java @Entity public class User { @Id private
@Table Specifies the table name and java @Entity @Table(name = "users") public
other metadata for the entity. class User { @Id private Long id; }
@Id Marks a field as the primary key java @Entity public class User { @Id private
@Column Specifies the column name for a java @Column(name = "username", nullable =
attributes.
@Basic Marks a field as a basic mapping java @Basic private String name;
(default).
@Transient Excludes a field from being java @Transient private String temporaryData;
relationship between
two entities.
entities.
Annotation Purpose Example
entities.
many relationship
between entities.
@JoinColumn Specifies the foreign java @ManyToOne @JoinColumn(name = "user_id") private User
relationship.
the database.
@MapKey Specifies a key for a Map collection. java @OneToMany private Map<String,
Order> orders; @MapKey(name =
"orderNumber")
@Lob Marks a field as a large object (BLOB java @Lob private String description;
or CLOB).
Annotation Purpose Example
@Cacheable Enables caching for an java @Cacheable public class Product { @Id private Long
behavior.