@Temporal and Date Mapping in JPA
Fast recall
Quick revision
Core answer
Whether you know @Temporal is legacy-only and that java.time maps automatically, plus Instant vs LocalDateTime for timezones
Putting @Temporal on a LocalDate field, or using LocalDateTime for global timestamps where Instant (UTC) is correct
Explain why java.time is preferred (immutable, thread-safe) and when Instant beats LocalDateTime
Interview-ready guide
Interview answer
Legacy Date can represent both a date and a time, so JPA needs @Temporal to know which SQL temporal type is intended. java.time types are clearer: LocalDate represents a date without a time zone, LocalDateTime represents a local date and time, and OffsetDateTime includes an offset. Do not add @Temporal to these types. For audit timestamps, confirm how the selected provider maps Instant or OffsetDateTime and which time zone the JDBC driver and database use; a Java type name alone does not guarantee UTC storage.
@Temporal and Date Mapping in JPA
Direct Answer
@Temporal is used with legacy java.util.Date or Calendar to choose DATE, TIME, or TIMESTAMP. Modern JPA maps supported java.time types such as LocalDate, LocalTime, LocalDateTime, OffsetTime, and OffsetDateTime without @Temporal. Instant support depends on the JPA version and provider, so verify the provider and database column semantics.
Common Mistakes & Pitfalls
@TemporalonLocalDate— invalid;@Temporalonly applies tojava.util.Date/Calendar. Remove it.LocalDateTimefor global timestamps — it has no timezone; useInstant(UTC) for cross-timezone events.- Sticking with
java.util.Date— mutable, not thread-safe; preferjava.timein new code. - Assuming a timezone — be deliberate: store UTC (
Instant) and convert at the edges.
Check your understanding
Answer these without looking back at the article.
- How does LocalDateTime map to a database column?
- What is @CreationTimestamp in Hibernate?
- Why is java.time preferred over java.util.Date?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.