From: David Rees <drees76@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Timestamp Problems
Date: Wed, 23 Jul 2008 13:00:40 -0700
Message-ID: <72dbd3150807231300w60e35ba9xc512930146481718@mail.gmail.com> (raw)
I've got an application which uses timestamps (without timezones) and
uses Hibernate to abstract away all the raw SQL code. A timestamp
field is mapped to a java.util.Date object. Versions in use:
PostgreSQL 8.3.3
JDBC Driver 8.3-603.jdbc4
Hibernate 3.2.6
Java 1.6.0_07 on Linux
A problem which recently cropped up on one development machine (and I
haven't been able to duplicate the issue off this machine) is that for
some reason the timestamp that gets inserted in to the database gets
converted to UTC. The timezone is explicity set by using the TZ
environment variable to America/New_York, the same issue occurs when
passing the -Duser.timezone=America/New_York parameter to the JVM.
What is strange is that this does not happen all the time, and that it
only affects this one particular column!
I did a search of the archives and found a few similar issues, but
they seemed to occur all the time, not periodically.
Here's a sample of what happens. Timestamp 1/2 are from the same
column/row, but before/after the database update and refresh. I
haven't modified the timestamp. I've looked at the raw SQL, and the
date is indeed getting converted to UTC (4 hours diff in this case).
Timestamp 1 = 2008-07-23 18:33:59.0
Update & Refresh
Timestamp 2 = 2008-07-23 22:33:59.0
What's strange is that if I take the date and create a new Date using
the original's getTime function, it looks like this:
Timestamp 1 = 2008-07-23 18:33:59.0 - new Date: Wed Jul 23 18:33:59 EDT 2008
Update & Refresh
Timestamp 2 = 2008-07-23 22:33:59.0 - new Date: Wed Jul 23 18:33:59 EDT 2008
Yeah, that's right, getTime() is returning the same value even though
toString() prints different values and different values get inserted
in to the database!
Even if I modify the timestamp, the same issue can crop up with the
exact same symptoms.
After a lot of troubleshooting, I've finally figured out that by
disabling the stored procedure cache used by Hibernate (I've
configured Hibernate to use c3p0's database connection pool and
prepared statement cache) this issue doesn't crop up any more.
Anyone see this before? Any idea where the bug lies?
Thanks
-Dave
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: drees76@gmail.com
Subject: Re: Timestamp Problems
In-Reply-To: <72dbd3150807231300w60e35ba9xc512930146481718@mail.gmail.com>
References: <72dbd3150807231300w60e35ba9xc512930146481718@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox