gpt4 book ai didi

java - Hibernate 和 ZonedDateTime

转载 作者:行者123 更新时间:2023-12-02 10:46:24 25 4
gpt4 key购买 nike

我正在开发一个 Spring Boot 应用程序,一个 REST API。

到目前为止,我将实体日期时间映射为 LocalDateTime。但它需要有区域时间信息,所以我想我应该使用 ZonedDateTime 相反。但我担心实际使用的是哪个区时间。由于数据库字段具有以下格式:2004-12-20 18:00:00,因此区域时间是根据当前计算机计算的(如 documentation 上的建议)。

为了避免任何灾难,应使用的区域时间是在数据库上配置的时间。 如何配置实体的 ZonedDateTimes 以采用特定区域时间?

最佳答案

如下面的链接所述,您必须全局配置 hibernate 属性 hibernate.jdbc.time_zone (在 hibernate 5 中)

https://www.thoughts-on-java.org/hibernate-tips-whats-the-best-way-to-persist-a-zoneddatetime/

按照描述,对特定实体的进一步设置将被忽略。

关于java - Hibernate 和 ZonedDateTime,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52533465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com