@Temporal is a JPA annotation used to tell the persistence provider how to map a legacy java.util.Date or java.util.Calendar field to a SQL column type -- as a DATE, TIME, or TIMESTAMP. It exists because those older Java types don't inherently distinguish between a date, a time, and a full timestamp the way the SQL column types do.
Key Points: • @Temporal takes a TemporalType value: DATE, TIME, or TIMESTAMP. • It only applies to java.util.Date and java.util.Calendar fields, not to the newer java.time types. • Modern JPA (2.2+) and Java 8's java.time classes (LocalDate, LocalDateTime, LocalTime) map automatically without needing @Temporal, since their type already implies the correct SQL mapping. • Omitting @Temporal on a java.util.Date field typically defaults to a TIMESTAMP mapping, which may not be what you want for a date-only value.
Example: An Employee entity storing a hire date as java.util.Date would annotate that field with @Temporal(TemporalType.DATE) so it maps to a SQL DATE column instead of a full timestamp with an unwanted time component.
Code Example:
@Entity
public class Employee {
@Id
private Long id;
@Temporal(TemporalType.DATE)
private Date hireDate;
@Temporal(TemporalType.TIMESTAMP)
private Date lastLoginAt;
}Interview Tip: A concise interview answer is:
"@Temporal tells JPA how to map a legacy java.util.Date or Calendar field to SQL as DATE, TIME, or TIMESTAMP, since those Java types alone don't specify that precision. In new code I'd prefer java.time types like LocalDate or LocalDateTime, which map automatically without needing @Temporal at all."