H2在初始化时插入时间戳

时间:2018-12-06 13:13:00

标签: java spring-boot h2

我想将时间戳记插入H2表,简单的@Entity-

import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;

@Entity
public class TaxValuesEntitiy {
    @Id
    @GeneratedValue
    private Long id;
    private String countryCode;
    private double taxValue;
    private Timestamp creationAt;
    private Timestamp modifedAt;
}

还有一个简单的data.sql-

insert into TAX_VALUES_ENTITIY
values(10001,'US', 30.22, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());

insert into TAX_VALUES_ENTITIY
values(10002,'IL', 32.78, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP());

完整的错误日志-

Caused by: org.h2.jdbc.JdbcSQLException: Cannot parse "TIMESTAMP" constant "30.22"; SQL statement:
insert into TAX_VALUES_ENTITIY values(10001,'US', 30.22, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) -- (10001, 'US', 30.22, CURRENT_TIMESTAMP(), CURRENT_TIMESTAMP()) [22007-197]
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:357) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.message.DbException.get(DbException.java:168) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.value.ValueTimestamp.parse(ValueTimestamp.java:147) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.value.Value.convertTo(Value.java:1071) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.table.Column.convert(Column.java:177) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.command.dml.Insert.insertRows(Insert.java:166) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.command.dml.Insert.update(Insert.java:134) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.command.CommandContainer.update(CommandContainer.java:102) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.command.Command.executeUpdate(Command.java:261) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.jdbc.JdbcStatement.executeInternal(JdbcStatement.java:233) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.jdbc.JdbcStatement.execute(JdbcStatement.java:205) ~[h2-1.4.197.jar:1.4.197]
    at com.zaxxer.hikari.pool.ProxyStatement.execute(ProxyStatement.java:95) ~[HikariCP-3.2.0.jar:na]
    at com.zaxxer.hikari.pool.HikariProxyStatement.execute(HikariProxyStatement.java) ~[HikariCP-3.2.0.jar:na]
    at org.springframework.jdbc.datasource.init.ScriptUtils.executeSqlScript(ScriptUtils.java:486) ~[spring-jdbc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    ... 36 common frames omitted
Caused by: java.lang.IllegalArgumentException: 30.22
    at org.h2.util.DateTimeUtils.parseDateValue(DateTimeUtils.java:345) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.util.DateTimeUtils.parseTimestamp(DateTimeUtils.java:460) ~[h2-1.4.197.jar:1.4.197]
    at org.h2.value.ValueTimestamp.parse(ValueTimestamp.java:145) ~[h2-1.4.197.jar:1.4.197]
    ... 47 common frames omitted

0 个答案:

没有答案