Application server (JVM) running in time zone: Europe/Dublin
- TimeZone.getDefault().getID()
Time zone for JDBC connections set for Spring / Hibernate using the configuration property:
spring.jpa.properties.hibernate.jdbc.time_zone=UTC
Java Entity:
@Column(name = "local_time")
private LocalTime localTime;
@Column(name = "local_date_time")
private LocalDateTime localDateTime;
@Column(name = "offset_time")
private OffsetTime offsetTime;
Java values debugged on application server (JVM) ..
LocalTime
- time
SQL type:
// LocalTime.ofInstant(now, Clock.systemDefaultZone().getZone())
01:32:13.283256
LocalDateTime
- timestamp
SQL type:
// LocalDateTime.ofInstant(now, Clock.systemDefaultZone().getZone())
2022-12-06T01:32:13.283256
OffsetTime
- time with time zone
SQL type:
// OffsetTime.ofInstant(now, Clock.systemDefaultZone().getZone())
01:32:13.283256Z
Database configured to use UTC:
postgres=# select name, setting, source from pg_settings where name='TimeZone';
name | setting | source
----------+---------+--------------------
TimeZone | Etc/UTC | configuration file
Query database (PostgreSQL) for values:
select * from item;
id | local_time | local_date_time | offset_time
----+------------+----------------------------+-------------
1 | 00:32:13 | 2022-12-06 01:32:13.283256 | 00:32:13+00
Why are the column values for local_time
and offset_time
1 hour behind UTC? Shouldn't they be the same as local_date_time
i.e 01:32
rather than 00:32
local_date_time
is the only column with correct value when directly querying the database. Why is that?