Entity Annotations Flashcards

1
Q

@Entity

A

Maps to a table in the database.
@Entity
public class User {
@Id
private Long id;
private String name;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

@Table

A

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;
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

@Id

A

Marks a field as the primary key of the entity

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

@GeneratedValue

A

Specifies the strategy for automatically generating primary key values.
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

@Column

A

Maps a field to a column in the database table.
@Column(name = “user_name”, length = 100, nullable = false)
private String name;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

@Transient

A

Marks a field to be ignored by JPA (i.e., not persisted to the database).
@Transient
private String temporaryData;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

@Version

A

Used for optimistic locking to manage concurrent updates to the same data.
@Version
private Long version;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly