[
https://issues.jboss.org/browse/HIBERNATE-170?page=com.atlassian.jira.plu...
]
nimo stephan commented on HIBERNATE-170:
----------------------------------------
I guess, a simpler solution would be to use the correct columnDefinition for
OffsetDateTime and ZonedDateTime by default. Actually, user must manually put
columnDefinition = "TIMESTAMP WITH TIME ZONE" to add the offset of
OffsetDateTime. But if db supports it, hibernate can add the correct columnDefinition by
default. Actually it uses for all types of java dates the columnDefinition of
"TIMESTAMP" which is not correct for OffsetDateTime and ZonedDateTime.
{code:java}
@Column(name = "timestamp", columnDefinition = "TIMESTAMP WITH TIME
ZONE")
private OffsetDateTime timestamp;
{code}
Support "TIMESTAMP WITH TIME ZONE" for OffsetDateTime and
ZonedDateTime
-----------------------------------------------------------------------
Key: HIBERNATE-170
URL:
https://issues.jboss.org/browse/HIBERNATE-170
Project: Hibernate Integration
Issue Type: Enhancement
Reporter: nimo stephan
Assignee: Steve Ebersole
Priority: Major
Something like this is supported in JPA 2.2:
{code:java}
@Column(name = "timestamp")
private OffsetDateTime timestamp;
{code}
However, the offset is NOT persisted in the database even if the database could support
it. For example, when using H2 database, then Hibernate could map this
"OffsetDateTime" to the sql datatype "TIMESTAMP WITH TIME ZONE"
(because H2 supports it) instead of the datatype "TIMESTAMP".
Actually, user assumes that when using "OffsetDateTime" with JPA Annotation,
JPA maps the offset as well. But this is not the case. Hibernate could also integrate a
fallback for databases which does NOT support "TIMESTAMP WITH TIME ZONE". On
schema generation, it could create and store something like "OffsetDateTime" or
"ZonedDateTime" into two columns to avoid this manual mapping:
{code:java}
@Column(name = "created_on")
private Instant timestamp;
@Column(name = "display_offset")
private int offset;
{code}
Hibernate can make use of its own "HibernateCompositeType" to store one
property (OffsetDateTime) into two sql columns (timestamp and offset).
With the solution above (by using either "TIMESTAMP WITH TIME ZONE" or the
fallback), Hibernate/JPA could map the "OffsetDateTime" and
"ZonedDateTime" correctly and completely with an offset or timezone.
--
This message was sent by Atlassian Jira
(v7.13.8#713008)