In Java, with JPA2, which class should be used to store date information?

There are three options that I see for date processing in Java, but maybe I will show you some better alternatives.

  • java.util.Date is good, but it is a very simple class with many design flaws.
  • java.util.Calendar - which is slightly better, but still really clumbsy to work with
  • JODA time - what is better to work with, but I'm not sure how much it will persist using JPA2

I would like to use JODA Time, because these are promises a simpler API, but persistence is more important, so I would be well versed in Calendar or Date if JODA Time is not saved.

Ultimately, I need something that is stored in the database as a date, preferably with an easy-to-use API.

+3
source share
3 answers

java.util.Calendar is saved with JPA2 as well as with java.util.Date, just make sure you add the @Temporal annotation to the property. JODA time preservation is better supported in Hibernate, however I don't think it supports temporary optimization queries included in some relational databases, so if you plan to request a date attached to java.util objects, it will be your best choice. If you do not plan to query this column, any serialization object can be saved using JPA.

0
source

We have JODA LocalDate sleep mode directly. Of course, there is some kind of configuration and something to do. You can watch this project: Joda-Time Hibernate

+1
source

java.util.Date POJO, Joda Time .

0

Source: https://habr.com/ru/post/1783943/


All Articles