-
Notifications
You must be signed in to change notification settings - Fork 6
ZonedDateTime emulation
A lot of JDBC drivers only support OffsetDateTime
and not ZonedDateTime
. However ZonedDateTime
support can be emulated using a TIMESTAMP WITH TIME ZONE
column holding the timestamp and a VARCHAR
field holding the zone id.
The threeten-jpa-zoned-hibernate
provides the ZonedDateTimeType
Hibernate composite type which maps two such columns to a ZonedDateTime
field.
You need two columns to hold the timestamp in UTC and the zone id. On our JVM the longest zone id fits in VARCHAR(32)
but you can also make the column wider
TIMESTAMP_UTC TIMESTAMP WITH TIME ZONE,
ZONE_ID VARCHAR(32),
On the Java side you have to set the type an map both columns
@Type(type = ZonedDateTimeType.NAME)
@Columns(columns = {
@Column(name = "TIMESTAMP_UTC"),
@Column(name = "ZONE_ID")
})
private ZonedDateTime zonedDateTime;
It is important that the TIMESTAMP WITH TIME ZONE
column is the first one and the VARCHAR
is the second one.
Have a look at the schema sample and the mapping example on how to use it.