[jboss-jira] [JBoss JIRA] (HIBERNATE-170) Support "TIMESTAMP WITH TIME ZONE" for OffsetDateTime and ZonedDateTime

nimo stephan (Jira) issues at jboss.org
Thu Oct 24 14:08:00 EDT 2019


nimo stephan created HIBERNATE-170:
--------------------------------------

             Summary: 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


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)


More information about the jboss-jira mailing list