Sobes.tech
Junior — Middle

How is a temporary field within an entity denoted using annotations?

sobes.tech AI

Answer from AI

In Java, a transient field within an entity is usually marked with the @Transient annotation. This annotation indicates that the field should not be persisted to the database and is ignored during mapping.

Example:

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Transient;

@Entity
public class User {
    @Id
    private Long id;

    private String name;

    @Transient
    private String sessionToken; // transient field, not stored in DB

    // getters and setters
}

Thus, the sessionToken field will only be used in memory and will not be included in the database table.

How is a temporary field within an entity denoted… - sobes.tech