I am attempting to insert unique UTC dates crossing a DST boundary,
and receive a unique constraint violation.

Upon investigation, it appears H2 is incorrectly adjusting the
timestamp when calling JdbcPreparedStatement.setTimestamp(int
parameterIndex, java.sql.Timestamp x, Calendar calendar) (line 654).

Environment details:
H2 1.3.158
java version "1.6.0_24"
I am running H2 in-memory, oracle mode
I have a table which has a timestamp column (UTC) with a unique
constraint.
My system timezone is PST/PDT

My scenario is the following:

I attempt to insert 15 minute intervals starting 2010-03-13 00:00:00.0
through 2010-03-16 00:00:00.0 (crossing DST Boundary) via iBatis:

    Timestamp timestamp = new Timestamp(date.getTime());
    setter.setTimestamp(timestamp, getCalendarUTC());

I receive the following exception:
    --- Cause: org.h2.jdbc.JdbcSQLException: Unique index or primary
key violation: "PRIMARY_KEY_3 ON PUBLIC.LP_INTERVALS(CHANNEL_ID,
UTC_INTERVAL_TIME)"

I have narrowed the problem down to
DateTimeUtils.convertTimestampToUTC().  It seems that underlying long
value of timestamp is being modified by the calendar, which is
incorrect as it is already in GMT.

I have written the following to expose the problem:
@Test
public void test ()
{
        Date now = new Date();
        System.out.println (now.getTime());

        Timestamp x = new Timestamp(now.getTime());

        Calendar c =
Calendar.getInstance(TimeZone.getTimeZone("UTC"));

        ValueTimestamp v = (ValueTimestamp)
DateTimeUtils.convertTimestampToUTC (x, c);
        Timestamp y = v.getTimestamp();
        System.out.println (y.getTime());

        assert(x.getTime() == y.getTime()); // fails
}

The existence of the methodconvertTimestampToUTC confuses me a little,
since a timestamp value is already in GMT, what conversion needs to be
done?

-- 
You received this message because you are subscribed to the Google Groups "H2 
Database" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/h2-database?hl=en.

Reply via email to