[hibernate-dev] Should the LocalTimeType use the globally configured TimeZone?
Vlad Mihalcea
mihalcea.vlad at gmail.com
Fri Oct 5 04:46:19 EDT 2018
Hi
IMO no timezone conversion whatsoever should be applied when
> persisting LocalDateTime as it doesn't contain any TZ information.
That's not very easy to do since either the JDBC Driver or the database
engine might to the timezone conversion based on the underlying setting.
In fact I'd even recommend to use a string-based column type to store
> LDT, as it avoids these kinds of issues altogether.
Actually, a Long (BigInt) column type with the epoch would be more suitable
than a CHAR-based column since it's more compact and achieves the same goal.
However, many clients will not want to store Date/Time in Int or String
columns as explained in the following article:
https://www.periscopedata.com/blog/better-sql-schema
Maybe introducing another value for "hibernate.jdbc.time_zone" ("as_is"?)
> that would also impact how we map timezone-less types, would be a good idea?
We would have to introduce a new configuration property as a strategy where
the current behavior is "legacy"
while the new one must be explicitly enabled.
Vlad
On Fri, Oct 5, 2018 at 11:17 AM Yoann Rodiere <yoann at hibernate.org> wrote:
> > In fact I'd even recommend to use a string-based column type to store
> > LDT, as it avoids these kinds of issues altogether.
>
> Or just, you know, "timestamp without timezone". Where possible.
>
> More to the point, I agree with Vlad's proposition, and I also think ORM
> should avoid messing with timezones as much as possible: when the user
> didn't provide one (LocalDate, LocalDateTime, Date), don't store one, when
> he provided one (ZonedDateTime, OffsetDateTime, Calendar, ...), store it
> exactly as provided. The goal being to return the exact value that was
> persisted when later retrieving the data.
> But unfortunately I think there is a lot of legacy behaviors that differ
> from this, so any attempt at "fixing" it would break compatibility and make
> someone angry.
>
> Maybe introducing another value for "hibernate.jdbc.time_zone" ("as_is"?)
> that would also impact how we map timezone-less types, would be a good idea?
>
>
> Yoann Rodière
> Hibernate NoORM Team
> yoann at hibernate.org
>
>
> On Fri, 5 Oct 2018 at 09:38, Gunnar Morling <gunnar at hibernate.org> wrote:
>
>> IMO no timezone conversion whatsoever should be applied when
>> persisting LocalDateTime as it doesn't contain any TZ information.
>>
>> If the target column type requires a TZ, it should be set to UTC,
>> storing the given value without any shift. I.e. the LDT value
>> 2007-12-03T10:15:30 should be stored as 2007-12-03T10:15:30 at UTC, no
>> matter what's the VM's timezone or any TZ related config. This allows
>> to retrieve the original value later on, also if e.g. the loading VM
>> is in a different TZ.
>>
>> In fact I'd even recommend to use a string-based column type to store
>> LDT, as it avoids these kinds of issues altogether.
>>
>> --Gunnar
>>
>>
>>
>>
>>
>> Am Fr., 5. Okt. 2018 um 07:15 Uhr schrieb Vlad Mihalcea
>> <mihalcea.vlad at gmail.com>:
>> >
>> > Hi,
>> > While reviewing this Jira issue:
>> >
>> > https://hibernate.atlassian.net/browse/HHH-12988
>> >
>> > and further discussing it via Twitter, I wonder if we should persist
>> > LocalTime as-is without any TimeZone transformation
>> > that may be done if we enable `hibernate.jdbc.time_zone`?
>> >
>> > According to the Date/Time API, LocalTime should not be relative to any
>> > TimeZone.
>> >
>> > If we make this change, it means we need to use a LocalTime SQL
>> descriptor
>> > that ignores the jdbc.time_zone property,
>> > and the change is going to break compatibility as well.
>> >
>> > Vlad
>> > _______________________________________________
>> > hibernate-dev mailing list
>> > hibernate-dev at lists.jboss.org
>> > https://lists.jboss.org/mailman/listinfo/hibernate-dev
>> _______________________________________________
>> hibernate-dev mailing list
>> hibernate-dev at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/hibernate-dev
>>
>
More information about the hibernate-dev
mailing list