Spring Boot 2.0,H2,无法在现有的 H2 数据库文件上启动应用程序
Spring Boot 2.0, H2, Unable to start app on existing H2 DB file
我正在将我的应用程序从 Spring Boot 1.4.x 迁移到 2.0.0。
在我们的开发环境中,我们 运行 文件 db 上的 H2,如下面的调试日志所示。我可以 运行 使用 ddl-auto: create with an in MEM db 的应用程序,但是当尝试使用我现有的 H2 文件时,我收到以下错误:
14:59:21.440 [] [] [main] DEBUG org.hibernate.loader.collection.plan.CollectionLoader - Static select for collection com.lmig.cortex.domain.entities.EmrProvisioning.associatedBuckets: select associated0_.emr_provisioning_id as emr_prov1_26_0_, associated0_.bucket_name as bucket_n2_26_0_, associated0_.is_ro as is_ro3_26_0_ from emr_associated_buckets associated0_ where associated0_.emr_provisioning_id=?
14:59:21.502 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery.............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - driverClassName................."org.h2.Driver"
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailFast..........true
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbc4ConnectionTest.............false
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:h2:file:~/API;FILE_LOCK=FS;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........com.zaxxer.hikari.metrics.micrometer.MicrometerMetricsTrackerFactory@1da5c19d
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutorService........internal
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - schema..........................none
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - username........................"sa"
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
14:59:21.504 [] [] [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
14:59:21.530 [] [] [main] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Failed to create/setup connection: Constraint "FK5FKLEKY5P9R43SW8TI8CRLYXG" already exists; SQL statement:
这是我的配置失败的样子:
datasource:
url: jdbc:h2:file:~/API;FILE_LOCK=FS;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL
driver-class-name: org.h2.Driver
username: sa
password:
continue-on-error: true
jpa:
database-platform: H2
hibernate:
ddl-auto: update
h2:
console:
enabled: true
附加信息:
我可以删除我的 h2 数据库文件,运行 生成新数据库文件的应用程序。一切都很好,我可以毫无问题地重新 运行 应用程序。我删除这些新文件,将旧文件移回来。同样的问题。这些文件中是否有一个地方包含已执行的有关 actions/updates 的元数据?也许我可以调整它?
从SpringBoot 1.4.7 到 2.0.0,H2 从 1.4.196 升级到 1.4.197。
如果没有您的 h2 文件,很难确定是哪一个,但是 changelog list 从 1.4.196 到 1.4.197 中的一项是导致您出现问题的原因。
如果您想保留您的数据,一种解决方案是将它们导出为 SQL 语句(请参阅 How in H2DB get sql dump like in MySql?)并使用 H2 1.4.197 重新导入它们。
我正在将我的应用程序从 Spring Boot 1.4.x 迁移到 2.0.0。
在我们的开发环境中,我们 运行 文件 db 上的 H2,如下面的调试日志所示。我可以 运行 使用 ddl-auto: create with an in MEM db 的应用程序,但是当尝试使用我现有的 H2 文件时,我收到以下错误:
14:59:21.440 [] [] [main] DEBUG org.hibernate.loader.collection.plan.CollectionLoader - Static select for collection com.lmig.cortex.domain.entities.EmrProvisioning.associatedBuckets: select associated0_.emr_provisioning_id as emr_prov1_26_0_, associated0_.bucket_name as bucket_n2_26_0_, associated0_.is_ro as is_ro3_26_0_ from emr_associated_buckets associated0_ where associated0_.emr_provisioning_id=?
14:59:21.502 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - HikariPool-1 - configuration:
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - allowPoolSuspension.............false
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - autoCommit......................true
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - catalog.........................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionInitSql...............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTestQuery.............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - connectionTimeout...............30000
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSource......................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceClassName.............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceJNDI..................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - dataSourceProperties............{password=<masked>}
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - driverClassName................."org.h2.Driver"
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckProperties...........{}
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - healthCheckRegistry.............none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - idleTimeout.....................600000
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailFast..........true
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - initializationFailTimeout.......1
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - isolateInternalQueries..........false
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbc4ConnectionTest.............false
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - jdbcUrl.........................jdbc:h2:file:~/API;FILE_LOCK=FS;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - leakDetectionThreshold..........0
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - maxLifetime.....................1800000
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - maximumPoolSize.................10
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - metricRegistry..................none
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - metricsTrackerFactory...........com.zaxxer.hikari.metrics.micrometer.MicrometerMetricsTrackerFactory@1da5c19d
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - minimumIdle.....................10
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - password........................<masked>
14:59:21.503 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - poolName........................"HikariPool-1"
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - readOnly........................false
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - registerMbeans..................false
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutor...............none
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - scheduledExecutorService........internal
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - schema..........................none
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - threadFactory...................internal
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - transactionIsolation............default
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - username........................"sa"
14:59:21.504 [] [] [main] DEBUG com.zaxxer.hikari.HikariConfig - validationTimeout...............5000
14:59:21.504 [] [] [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
14:59:21.530 [] [] [main] DEBUG com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Failed to create/setup connection: Constraint "FK5FKLEKY5P9R43SW8TI8CRLYXG" already exists; SQL statement:
这是我的配置失败的样子:
datasource:
url: jdbc:h2:file:~/API;FILE_LOCK=FS;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=PostgreSQL
driver-class-name: org.h2.Driver
username: sa
password:
continue-on-error: true
jpa:
database-platform: H2
hibernate:
ddl-auto: update
h2:
console:
enabled: true
附加信息:
我可以删除我的 h2 数据库文件,运行 生成新数据库文件的应用程序。一切都很好,我可以毫无问题地重新 运行 应用程序。我删除这些新文件,将旧文件移回来。同样的问题。这些文件中是否有一个地方包含已执行的有关 actions/updates 的元数据?也许我可以调整它?
从SpringBoot 1.4.7 到 2.0.0,H2 从 1.4.196 升级到 1.4.197。
如果没有您的 h2 文件,很难确定是哪一个,但是 changelog list 从 1.4.196 到 1.4.197 中的一项是导致您出现问题的原因。
如果您想保留您的数据,一种解决方案是将它们导出为 SQL 语句(请参阅 How in H2DB get sql dump like in MySql?)并使用 H2 1.4.197 重新导入它们。