0 Replies Latest reply on Mar 18, 2006 12:15 PM by Jens Elkner

    Persistence: Timezone property ?

    Jens Elkner Apprentice

      Is there a property to set the default timezone to be used in the persistence.xml?

      My problem is, that I do not want to have to command a user, under which timezone he has
      to run its application server (since other apps my rely on a certain one).

      However, the only reliable way to store datetimes reusable in a database is, that the application follows a simple rule:all datetimes have to be stored wrt. one and the same timezone. Since Java Date and Calendar operate always on time in millis since 01.01.1970 00:00:00,000 GMT, it makes of course sense to use GMT as the applications standard Timezone , to avoid the overhead of converting those values back and forward.

      Unfortunately, hibernate uses probably DateFormat.get*Instance() to convert Calendar.getTime() /Date into the String, understood by the database. The problem is now, that in this case the default timezone gets used and this (if not GMT) adds an offset to the actual Calendar.getTime() aka Date. So it stores a completely different value, than submitted by the application and its only a question of time ;-), until the chaos starts.

      So, at least as long as hibernate has this misbehavior, one needs a way to tell hibernate aka EntityManager, which timezone it should use for storing datetimes. Or should we start to store long values aka time in millis and avoid using temporal types with hibernate at all ?