jakartaee / persistence

https://jakartaee.github.io/persistence/
Other
187 stars 55 forks source link

precision of SQL time and timestamp types #563

Closed gavinking closed 4 months ago

gavinking commented 6 months ago

JPA provides no way to specify the precision of SQL time and timestamp types (in fractional seconds).

For some time Hibernate has been abusing the precision member of the @Column annotation for this, but this has a bit of a problem in that its default value is precision=0 [which is actually intended to be interpreted as null] and 0 is both (a) a meaningful/useful value, and (b) not the best default for a timestamp.

Therefore, I think we should formalize something in the JPA spec, by defining:

  1. the default precision for a time (0 digits of fractional second precision, IMO)
  2. the default precision for a timestamp (3-6 digits of fractional second precision, depending on the database, IMO)
  3. a way for the user to explicitly specify the precision.

Now, there's three options I can think of for part 3:

The disadvantage of the first option is it's in principle a breaking change.

sebersole commented 6 months ago

introduce a new @FractionalSeconds annotation.

:+1:

This is the approach we are taking in Hibernate fwiw - https://hibernate.atlassian.net/browse/HHH-17575