Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 14216106AC for ; Tue, 3 Dec 2013 16:31:45 +0000 (UTC) Received: (qmail 97522 invoked by uid 500); 3 Dec 2013 16:31:44 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 96491 invoked by uid 500); 3 Dec 2013 16:31:39 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 96459 invoked by uid 99); 3 Dec 2013 16:31:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Dec 2013 16:31:38 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of diogocasado@gmail.com designates 209.85.223.180 as permitted sender) Received: from [209.85.223.180] (HELO mail-ie0-f180.google.com) (209.85.223.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 03 Dec 2013 16:31:30 +0000 Received: by mail-ie0-f180.google.com with SMTP id tp5so23188643ieb.25 for ; Tue, 03 Dec 2013 08:31:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=wVOhYvHkJn7RuhBfO5audY5DEeqPXuJi1JT7Crl9tkc=; b=B9Qr1BADkKdV+/kYYmvRS1yGVLj5+SPK7mMl8WlgYrERzX8VIDL8Cvg6lHH0JDuMn+ 9V1wA8RSAZG1WYZoqOOxIISzZZ7JnJrKX/ckURngsJmli4fE6NDmsPGeFCP9HCTcxQdJ fBuRhhWOF8QOT2V8rKTy4Ml8L2ke7ewwMzodxq8eSXOrln7E0xbHQlSRIgeMq4hD+q6H lERKMUR4MFeUAHucQ6lNtDu4omaORl25HzJyPfm7WBmYU1QR72u067SoRbtqWXXRBRa8 aMWBbO1BxvzeXvNr2N2kREwn9UPiRKRZyQhisajlEGisK5LqLpLKk20kdvehQ7NOINqy O3MQ== MIME-Version: 1.0 X-Received: by 10.50.176.137 with SMTP id ci9mr3471815igc.31.1386088269228; Tue, 03 Dec 2013 08:31:09 -0800 (PST) Received: by 10.64.7.143 with HTTP; Tue, 3 Dec 2013 08:31:09 -0800 (PST) Date: Tue, 3 Dec 2013 14:31:09 -0200 Message-ID: Subject: yet another DATETIME timezone question related to openjpa+mysql From: Diogo Casado To: users@openjpa.apache.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Checked: Checked by ClamAV on apache.org Hello guys, I just finished migrating from Hibernate to OpenJPA since we will use Tomee from now on. I've been researching/testing this problem for quite some time now. Could use some help.. I have a DATETIME field in a MySQL database that must be stored as utc time. This is standard good practice I guess. But the database server is not in utc time and cannot change server timezone. I have to connect to several databases but they all have different timezones. I'm using the following annotation: @Column @Temporal(TemporalType.TIMESTAMP) //Does not affect result private Date dateTimeUtc; What happens is that when I fetch/update this field.. the Date object millisecond value gets adjusted to database session timezone and an invalid value is stored. Just highlighting that DATETIME is not influenced by server timezone conversion while TIMESTAMP is.. For example: Let's say I need to store 2013-12-03 12:00:00 UTC. I use JodaTime to convert my local time (adjustable depending on user preferences, cannot change default instance timezone) to utc. An example: new DateTime().withZone(DateTimeZone.UTC).withDate(2013, 12, 3).withTime(12, 0, 0, 0).toDate(); -> this is set in the above field. My date object is correct, nice milliseconds since epoch.. (1386072000000 checked with debug). The database server is running on GMT-2 (in this case both jvm and database are on the same timezone). The value stored is 2013-12-03 10:00:00 instead of 2013-12-03 12:00:00. The opposite: I go there and update manually the field to 2013-12-03 12:00:00. I fetch the entity the Date object has +2hs (millis 1386079200000). I can do: new DateTime(dateTimeUtc, DateTimeZone.UTC) or just look at Date's local representation and it shows 2013-12-03-12:00:00 which means Date+2h(session timezone)-2h(jvm timezone) (confusing I know.. but it's behaving exactly this way). How can I avoid this behavior? I previously worked with plain Date object with hibernate and it was ok. >From other posts.. everyone come up with: change your server timezone to utc and that in my case is not an option. So.. help? Thanks! - Diogo