Joda time DateTime incorrectly stores in database

fedor.belov picture fedor.belov · Apr 9, 2012 · Viewed 10.2k times · Source

I'm storing JodaTime DateTime field to timestamptz column by using org.jadira.usertype:usertype.jodatime:1.9. App server has +4 time zone. DB server +9 time zone. new DateTime() results in ${currentTime+1hour}+9 where +9 is time zone (correct value is ${currentTime+5hours)+9).

I haven't found any related topics. java.util.Date stores correctly.

Domain object has the following mapping property:

static mapping = {
    dateCreated sqlType:'timestamptz'
}

How can I store DateTime correctly?

Answer

Michal Z m u d a picture Michal Z m u d a · May 26, 2013

Just set JPA properties:

<property name="jadira.usertype.autoRegisterUserTypes"
          value="true"/>
<property name="jadira.usertype.databaseZone"
          value="jvm"/>
<property name="jadira.usertype.javaZone"
          value="jvm"/>