Skip to content

INSERT operation sets wrong data to TIMESTAMP WITH TIME ZONE column since version 3.2.0 #831

Description

@yoshida16729438

Describe the bug
If I execute DatabaseTester.setDataSet() and onSetup() with the dataset which includes timestamp with time zone column, the time zone of the data are effectively ignored, and inserted as if they were local time zone value.
It seems this occurs like :

  1. TimestampDataType::setSqlValue is invoked
  2. The value is converted into java.sql.Timestamp with typeCast() method.
    typeCast() method shifts the timestamp value with both of time zones from dataset and local time zone, and returns Timestamp value which is translated into the same instant of local time zone.
  3. Calendar for time zone from dataset is created
  4. statement.setTimestamp() is called with the Timestamp and Calendar.
    setTimestamp() internally clears the time zone shift from dataset which is calculated in step 2, and that will conclude into that as if the timestamp value in dataset was treated as local time zone and time zone in dataset is ignored.

To Reproduce
I've made a small project which reproduces the problem.
Please see this pull request which shows that DBUnit version 3.1.0 successes the test but 3.2.0 fails.

Steps to reproduce the behavior:

  1. dbUnit version
    3.2.0
  2. Database vendor and version
    H2 Database 2.4.240 with the reproduction project, and I've also checked with Oracle DB
  3. dbUnit data file rows and type
    Requires timestamp with time zone column.
    The time zone in the data must be different from the execution environment's time zone
  4. How run
    Just run mvn test -Ddbunit.version=3.X.0 with the reproduction project.
    If dbunit.version is 3.1.0, it will successfully be completed.
    If dbunit.version is 3.2.0 or 3.3.0, it will fail.

Expected behavior
Timestamp data must be persisted with correct time zone.

Additional context
It seems it can be fixed by getting Calendar instance by Calendar.getInstance() with no parameter in TimestampDataType, but I'm not sure if it breaks other logics or other column types support like TIMESTAMP WITHOUT TIME ZONE or TIMESTAMP WITH LOCAL TIME ZONE.
Related issue: #711

Since this is the first time reporting the bug of OSS, and I'm not a mother tongue English speaker, so maybe this description is not enough understandable. Sorry for inconvenience.

Metadata

Metadata

Assignees

Labels

Type

Projects

Status
Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions