jadira usertype timezone

hibernate, jodatime, spring

Solution

You need to set the property "jadira.usertype.databaseZone".

Either set it to an explicit timezone, or "jvm" to use whatever the default timezone of the JVM is.

<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>

Problem

I'm using jadira usertype + joda time in my project. I'm using hibernate + spring. My bean pojo use spring annotations as @CreatedDate and org.springframework.data.jpa.domain.support.AuditingEntityListener that automatically set the creation date on the bean when it is saved. I am in Europe/Rome Timezone but unfortunally in the db the date is stored as UTC, instead when I display the value on the client (javafx) the date is show in the correctly timezone. How can I store data in db in the correct timezone? Thanks very much.

Original source