我有一個Hibernate的Spring Boot應用程序。服務器時區是UTC。我需要用DST(夏令時)來使用歐洲/倫敦。我設置了在啓動時:LocalDateTime時區工作,而LocalTime不工作
TimeZone.setDefault(TimeZone.getTimeZone("Europe/London"));
而且與MySQL
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:mysql://localhost:3306/example?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&useTimezone=true&serverTimezone=Europe/London
name:
username: ****
password: ****
hikari:
data-source-properties:
cachePrepStmts: true
prepStmtCacheSize: 250
prepStmtCacheSqlLimit: 2048
useServerPrepStmts: true
hibernate.jdbc.time_zone: Europe/London
我不希望我的時間更改爲UTC連接。我需要留在DST,就是這樣。我的申請僅適用於英國,所以歐洲/倫敦足夠好。
問題是,當我有LocalDateTime例如:31.07.2017 14:00並將其存儲到數據庫,然後我在數據庫中具有完全相同的條目。但是,當我在14:00存儲LocalTime(單獨)時,它會在13:00保存在數據庫中。爲什麼它在現場轉換的時間?
UPDATE:
更多的調試後(加入兩行application.properties):
logging.level.org.hibernate.SQL=debug
logging.level.org.hibernate.type.descriptor.sql=trace
我看到Hibernate不轉換時間。它發送了14:00,但MySQL將它轉換爲13:00。有什麼建議麼?
謝謝@rlinden。這看起來像是MySQL單獨改變數值。我有連接參數serverTimezone =歐洲/倫敦強制使用歐洲/倫敦和它適用於DATETIME但不適用於時間。我的意思是,MySQL對DATETIME不做任何處理,但在TIME字段中更改值。我需要歐洲/倫敦的「CURRENT_TIMESTAMP」等。 – psalkowski