3

我在我的项目中使用 jadira usertype + joda time。我正在使用休眠+弹簧。我的 bean pojo 使用 spring 注释作为 @CreatedDate 和 org.springframework.data.jpa.domain.support.AuditingEntityListener 在保存时自动设置 bean 的创建日期。我在欧洲/罗马时区,但不幸的是,在数据库中,日期存储为 UTC,而不是当我在客户端(javafx)上显示值时,日期显示在正确的时区中。

如何在正确的时区将数据存储在 db 中?

非常感谢。

4

1 回答 1

5

您需要设置属性“jadira.usertype.databaseZone”。

将其设置为显式时区,或“jvm”以使用 JVM 的默认时区。

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
p:jpaProperties-ref="jpaProps" />

<util:properties id="jpaProps">
  <prop key="hibernate.show_sql">true</prop>
  <prop key="hibernate.format_sql">true</prop>
  <prop key="jadira.usertype.autoRegisterUserTypes">true</prop>
  <!-- defaults to storing UTC dates in DB otherwise -->
  <prop key="jadira.usertype.databaseZone">jvm</prop>
  <prop key="jadira.usertype.javaZone">jvm</prop>
</util:properties>
于 2013-07-26T03:23:11.893 回答