使用Java 8在Instant类型的基础H2中键入时出错

时间:2018-05-02 18:31:12

标签: java database spring h2

我有一个实体

public class UserEntity {
...
    @Basic(optional = false)
    @Column(name = "created", nullable = false, updatable = false)
    @CreatedDate
    private Instant created;

    @Basic
    @Column(name = "modified_date", nullable = false)
    @LastModifiedDate
    private Instant modifiedDate;
...
}

我使用命令

使用FlyWay迁移创建表
CREATE TABLE users (id  SERIAL NOT NULL, activation_token VARCHAR(255), avatar_id_in_cloud VARCHAR(255), avatar_provider VARCHAR(255), created DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), email VARCHAR(255) NOT NULL UNIQUE, email_change_token VARCHAR(255), enabled BOOLEAN NOT NULL, entity_version INTEGER NOT NULL, modified_date DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), new_email VARCHAR(255), password VARCHAR(255) NOT NULL, unique_id VARCHAR(255) NOT NULL UNIQUE, username VARCHAR(36) NOT NULL UNIQUE, PRIMARY KEY (id));

我在实体中将类型从Date更改为Instant,并在SQL查询中将其更改为

DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3)

他在编译期间抛出

    Migration V1__Base_Version.sql failed
-------------------------------------
SQL State  : 42001
Error Code : 42001
Message    : Syntax error in SQL statement "CREATE TABLE USERS (ID  SERIAL NOT NULL, ACTIVATION_TOKEN VARCHAR(255), AVATAR_ID_IN_CLOUD VARCHAR(255), AVATAR_PROVIDER VARCHAR(255), CREATED DATETIME([*]3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), EMAIL VARCHAR(255) NOT NULL UNIQUE, EMAIL_CHANGE_TOKEN VARCHAR(255), ENABLED BOOLEAN NOT NULL, ENTITY_VERSION INTEGER NOT NULL, MODIFIED_DATE DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), NEW_EMAIL VARCHAR(255), PASSWORD VARCHAR(255) NOT NULL, UNIQUE_ID VARCHAR(255) NOT NULL UNIQUE, USERNAME VARCHAR(36) NOT NULL UNIQUE, PRIMARY KEY (ID)) "; expected "FOR, UNSIGNED, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, CHECK, REFERENCES, ,, )"; SQL statement:
CREATE TABLE users (id  SERIAL NOT NULL, activation_token VARCHAR(255), avatar_id_in_cloud VARCHAR(255), avatar_provider VARCHAR(255), created DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), email VARCHAR(255) NOT NULL UNIQUE, email_change_token VARCHAR(255), enabled BOOLEAN NOT NULL, entity_version INTEGER NOT NULL, modified_date DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), new_email VARCHAR(255), password VARCHAR(255) NOT NULL, unique_id VARCHAR(255) NOT NULL UNIQUE, username VARCHAR(36) NOT NULL UNIQUE, PRIMARY KEY (id)) [42001-197]
Location   : db/migration/h2/V1__Base_Version.sql (C:\Users\Jonatan\Documents\GitHub\REST-Web-Services\web\out\production\classes\db\migration\h2\V1__Base_Version.sql)
Line       : 7
Statement  : CREATE TABLE users (id  SERIAL NOT NULL, activation_token VARCHAR(255), avatar_id_in_cloud VARCHAR(255), avatar_provider VARCHAR(255), created DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), email VARCHAR(255) NOT NULL UNIQUE, email_change_token VARCHAR(255), enabled BOOLEAN NOT NULL, entity_version INTEGER NOT NULL, modified_date DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), new_email VARCHAR(255), password VARCHAR(255) NOT NULL, unique_id VARCHAR(255) NOT NULL UNIQUE, username VARCHAR(36) NOT NULL UNIQUE, PRIMARY KEY (id))

2018-05-02 20:22:32.223  INFO 1992 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-05-02 20:22:32.229  WARN 1992 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [HikariPool-1 housekeeper] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
 java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1074)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
 java.lang.Thread.run(Thread.java:748)
2018-05-02 20:22:32.230  WARN 1992 --- [ost-startStop-1] o.a.c.loader.WebappClassLoaderBase       : The web application [ROOT] appears to have started a thread named [HikariPool-1 connection adder] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
 sun.misc.Unsafe.park(Native Method)
 java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
 java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
 java.util.concurrent.LinkedBlockingQueue.poll(LinkedBlockingQueue.java:467)
 java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1073)
 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1134)
 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

0 个答案:

没有答案