0

While using java.util.Date in a spring boot application, is it required to decorate with @Temporal annotation? For me, it worked without the annotation!

Can anyone clarify? As per my knowledge it needs to be decorated with the @Temporal annotation.

inquizitive
  • 622
  • 4
  • 21
asanka12
  • 43
  • 1
  • 7

1 Answers1

1

To my understanding of the question, you want to know when it is necessary to use the @Temporal annotation, and when it is not.

  • According to this documentation, the annotation is used on java.util data types. I have been using java.sql date and time objects, and they do not require this annotation.

  • The @Temporal annotation is a way of converting between java API for date and calendar information, and temporal types the database can understand. Please consult this other question for more info.

java.util.Date has date and time precision, and that is why you need to annotate it with @Temporal when persisting to a database data type of TIME or DATE.

If you are persisting a java.util.Date object to a database data type of TIMESTAMP, then that is probably why it works, since both types have the same precision.

Gabriel Robaina
  • 709
  • 9
  • 24