I had so many interesting new things to talk about in the summary of Jakarta Persistence 3.2 that I forgot to mention an important thing we’re taking away.

Support for java.util.Date, java.util.Calendar, java.sql.Date, java.sql.Time, and java.sql.Timestamp has been deprecated in JPA 3.2 and will be removed in a future release of the specification.

For reasons unknown to me, java.util.Date is not marked @Deprecated, though it clearly should have been deprecated back in 2014—​amazingly, its Javadoc doesn’t even mention the existence of java.time. Nevertheless, every experienced Java developer knows that java.util.Date is and has always been terrible, and that its friends in java.sql are even worse. Since the introduction of java.time, nobody should be writing new code involving java.util.Date or its subclasses.

JPA has required support for LocalDate, LocalTime, LocalDateTime, OffsetTime, and OffsetDateTime since version 2.2. Version 3.2 adds support for Instant and Year. These are the types you should use to represent dates, times, and datetimes in your entity classes.

Therefore, JPA 3.2 deprecates:

  • the @Temporal and @MapKeyTemporal annotations,

  • the TemporalType enumeration, and

  • all the overloads of Query.setParameter() which accept a TemporalType.

Let’s see if Java itself will follow our lead on this.

So if you’re still using java.util.Date, I have just one word of advice: stop.


Back to top