DBUnit inserting Timestamp default value in H2 Table parsing error

4.4k views Asked by At

When i try to use DBUnit to insert a record into a H2 table i get an Exception caused by:

Caused by: org.h2.jdbc.JdbcSQLException: 
  Cannot parse "TIMESTAMP" constant "1970-00-01"; 
  SQL statement: insert into PUBLIC.TABLE (COLX, COLY, COLZ) values (?, ?, ?)
Caused by: java.lang.IllegalArgumentException: 
  1970-0-1 at org.h2.util.DateTimeUtils.parseDateValue(DateTimeUtils.java:276)

None of the values are for the required timestamp column, so dbUnit seems to try to insert a default value which raises the problem. Note: the 1970-0-1 is not the 1970-00-01 as in the table description (see below).

I am not sure whre i could configure the behaviour. Anyways her's some of my setup which could help identify the error:

Create statement:

create table MYTABLE (
    "UUID" binary default random_uuid() not null,
    "COL2" varchar(18) not null,
    "COL3" varchar(20),
    "COL4" timestamp default '1970-00-01',
    ...

The DataSet XML (as said the three values are not including the timestamp column)

<dataset>
  <MYTABLE COLX="text" COLY="1" COLZ="Text"/>

i have also set

dbConfig.setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, new H2DataTypeFactory());

I was thinking of two possibilities: 1. Is dbUnit trying to parse the value from the column info? 2. Is there a standard default generator for timestamp/date fields in dbUnit?

So any ideas what i need to do to have the correct default value will be inserted?

1

There are 1 answers

2
Thomas Mueller On BEST ANSWER

There is no month 0. January is month 1. So you need to use '1970-01-01' instead of '1970-00-01'.