What is the @Temporal annotation used for?

@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

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.

@Entity
public class Employee {

    @Id
    private Long id;

    @Temporal(TemporalType.DATE)
    private Date hireDate;

    @Temporal(TemporalType.TIMESTAMP)
    private Date lastLoginAt;
}

Common Mistakes

Follow-up Questions

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.

Last updated: 11 November 2026

Previous question: What is the difference between findById() and getOne()?

Next question: How do you write a query method for sorting in Spring Data JPA?

More Spring Data JPA interview questions

All Spring Data JPA questions