jadira usertype timezone

dre*_*nda 3 spring hibernate jodatime

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

如何在正确的时区内以db存储数据?

非常感谢.

dan*_*ter 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>
Run Code Online (Sandbox Code Playgroud)