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
> <http://gordonizer.com>
>
>
> ------------------------------------------------------------------------------
>
> _______________________________________________
> Joda-interest mailing list
> Joda-interest@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/joda-interest
>
>
------------------------------------------------------------------------------
_______________________________________________
Joda-interest mailing list
Joda-interest@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/joda-interest

Reply via email to