Unfortunately, we need the time zone - either implicitly or explicitly - as
it's required in a bunch of different areas.

We dug deeper into the PersistentDateTimeTZ class and found that there's a
method nullSafeSet and it appears that even though the data type in postgres
is timestamp without time zone, you cannot get a timestamp out of the
database WITHOUT an implicit time zone value, in this case our local time,
and you have to do some really nasty/gross Java in order to convert it.

Lesson learned is do not store timestamps in the database without a time
zone.  We will most likely have to do a data migration to fix this and not
have to use nasty code.

--adam

On Thu, May 6, 2010 at 06:26, Sean Mitchell <s...@mitchwood.com> wrote:

> Hi Adam...
>
> I think you need to shed the dependency in the code on the timezone; you
> shouldn't need it. The Date object that Hibernate will get from JDBC should
> represent a moment in time, not a localized interpretation. Timezone only
> matters when you stick the date into the DB as a String, and when you output
> it from your Java code as a string.
>
> To do this, perhaps you could add another TIMESTAMP field to your table,
> and a trigger that updates it with a the correct time after insert. This
> would then be the field that you would map in Hibernate.
>
> Since you are using a DateTime instead of a Date, you'll need to create the
> DateTime using the the long "instant" value you get from your
> java.sql.Date.getTime().
>
> Cheers,
>
> Sean
>
> On Wed, May 5, 2010 at 11:50 PM, Adam Gordon <adam.n.gor...@gmail.com>wrote:
>
>> Long story short, due to a REALLY poor design by a subcontractor, our time
>> and time zone data are stored in separate fields in our postgres database.
>> The time field is timestamp without timezone and the time zone field is a
>> string (varchar).  The data is read as "the <time> at <time zone>" - meaning
>> the <time> is generic.  E.g., if <time> were '2010-05-03 18:04:00' and <time
>> zone> were 'America/New_York' then it would be May 3, 2010 at 6:04PM Eastern
>> Time.
>>
>> In a perfect world, I would like be able to pull both bits of data
>> simultaneously (via annotations) and store in an Entity field whereby the
>> field's datatype is a DateTime object set to the specified date and time at
>> the specified time zone.
>>
>> We've tried several different things but are seeing some really weird
>> behavior.  For example, if we add a listener to when the Entity is loaded so
>> that we can post process a separate date/time field, we notice that the time
>> is being pulled from the database in local time (Mountain Time) and then
>> 'converted' to the specified time zone - meaning the time is actually
>> adjusted - something we don't want.
>>
>> It seems like the only way to prevent this would be to have Hibernate
>> properly retrieve BOTH data fields and construct a DateTime object from both
>> values.  I think the issue is that DateTime must have a time zone whereas a
>> Java Date object does not and maybe this is the work-around until we can fix
>> our data.
>>
>> Anyone have some ideas on this?  Thanks.
>>
>> --adam
>>
>>
------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to