Liquibase maps ZonedDateTime as TIMESTAMP WITH TIME ZONE

76 Views Asked by At

I am using mvn liquibase:diff to generate the changests with the differences between my spring entities and the database.

Everything works fine except when I am using the ZonedDateTime type. mvn liquibase:diff generates a changeset with TIMESTAMP WITHOUT TIME ZONE, but it should be generating a TIMESTAMP WITH TIME ZONE. How can I specify that the mapping must be ZonedDateTime → TIMESTAMP WITH TIME ZONE, and LocalDateTime → TIMESTAMP WITHOUT TIME ZONE.

P.S. I am using PosgreSQL database. Thank you.

I am expecting that the mapping must be ZonedDateTime → TIMESTAMP WITH TIME ZONE, and LocalDateTime → TIMESTAMP WITHOUT TIME ZONE.

1

There are 1 best solutions below

1
On

No, not ZonedDateTime

ZonedDateTime is not defined in the JDBC mapping of Java classes to SQL types.

OffsetDateTime

OffsetDateTime is the class to use with a column of a type akin to the SQL standard type TIMESTAMP WITH TIME ZONE. See JDBC 4.2 specification.

Kind Components Standard SQL PostgreSQL Java
Moment date, time, offset TIMESTAMP WITH TIME ZONE TIMESTAMP WITH TIME ZONE OffsetDateTime
Not a moment date, time TIMESTAMP WITHOUT TIME ZONE TIMESTAMP WITHOUT TIME ZONE LocalDateTime

You said:

ZonedDateTime type. mvn liquibase:diff generates a changeset with TIMESTAMP WITHOUT TIME ZONE, but it should be generating a TIMESTAMP WITH TIME ZONE

No, it should not.

Only OffsetDateTime is mapped to TIMESTAMP WITH TIME ZONE in JDBC. The other two classes that represent a specific point on the timeline are not mapped in JDBC: Instant & ZonedDateTime.

The SQL Standard unfortunately used the word time zone, but actually meant offset from UTC.