Entity Annotations Flashcards
@Entity
Maps to a table in the database.
@Entity
public class User {
@Id
private Long id;
private String name;
}
@Table
Specifies the name of the database table to which an entity is mapped.
@Entity
@Table(name = “users”)
public class User {
@Id
private Long id;
private String name;
}
@Id
Marks a field as the primary key of the entity
@GeneratedValue
Specifies the strategy for automatically generating primary key values.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column
Maps a field to a column in the database table.
@Column(name = “user_name”, length = 100, nullable = false)
private String name;
@Transient
Marks a field to be ignored by JPA (i.e., not persisted to the database).
@Transient
private String temporaryData;
@Version
Used for optimistic locking to manage concurrent updates to the same data.
@Version
private Long version;