我正在使用 0.22.1 Exposed libs (core/dao/jdbc),当我使用“SchemaUtils.createMissingTablesAndColumns”时,我的表已创建,但出现异常。
如果我使用新列重新启动服务器,我会得到相同的异常并且不执行更新
查看堆栈跟踪:
Exception in thread "main" java.util.NoSuchElementException: Collection contains no element matching the predicate.
at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl$tableConstraints$$inlined$associateWith$lambda$1.invoke(JdbcDatabaseMetadataImpl.kt:170)
at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl$tableConstraints$$inlined$associateWith$lambda$1.invoke(JdbcDatabaseMetadataImpl.kt:13)
at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImplKt.iterate(JdbcDatabaseMetadataImpl.kt:164)
at org.jetbrains.exposed.sql.statements.jdbc.JdbcDatabaseMetadataImpl.tableConstraints(JdbcDatabaseMetadataImpl.kt:123)
at org.jetbrains.exposed.sql.vendors.VendorDialect$fillConstraintCacheForTables$1.invoke(Default.kt:639)
at org.jetbrains.exposed.sql.vendors.VendorDialect$fillConstraintCacheForTables$1.invoke(Default.kt:560)
at org.jetbrains.exposed.sql.statements.jdbc.JdbcConnectionImpl.metadata(JdbcConnectionImpl.kt:47)
at org.jetbrains.exposed.sql.Database.metadata$exposed_core(Database.kt:31)
at org.jetbrains.exposed.sql.vendors.VendorDialect.fillConstraintCacheForTables(Default.kt:639)
at org.jetbrains.exposed.sql.vendors.VendorDialect.columnConstraints(Default.kt:617)
at org.jetbrains.exposed.sql.SchemaUtils.addMissingColumnsStatements(SchemaUtils.kt:145)
at org.jetbrains.exposed.sql.SchemaUtils.createMissingTablesAndColumns(SchemaUtils.kt:241)
at org.jetbrains.exposed.sql.SchemaUtils.createMissingTablesAndColumns$default(SchemaUtils.kt:229)
at repository.database.DatabaseRepository$createTableAndColumn$1.invoke(DatabaseRepository.kt:36)
at repository.database.DatabaseRepository$createTableAndColumn$1.invoke(DatabaseRepository.kt:17)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$inTopLevelTransaction$1.invoke(ThreadLocalTransactionManager.kt:156)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$inTopLevelTransaction$2.invoke(ThreadLocalTransactionManager.kt:197)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:205)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:196)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt$transaction$1.invoke(ThreadLocalTransactionManager.kt:134)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.keepAndRestoreTransactionRefAfterRun(ThreadLocalTransactionManager.kt:205)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:106)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:104)
at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction$default(ThreadLocalTransactionManager.kt:103)
at repository.database.DatabaseRepository.createTableAndColumn(DatabaseRepository.kt:35)
at repository.database.DatabaseRepository.createAndUpdateDB(DatabaseRepository.kt:31)
at domain.database.PrepareDatabaseUseCase.performNow(PrepareDatabaseUseCase.kt:18)
at controller.MainController.<init>(MainController.kt:18)
at controller.MainControllerKt.main(MainController.kt:10)
我的表格很简单(仅用于测试):
import org.jetbrains.exposed.dao.id.IntIdTable
object UserTable: IntIdTable()
和
import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.Column
object SpaceTable: IntIdTable() {
val userIdColumn: Column<EntityID<Int>> = reference("userId", UserTable.id)
}
当我尝试“SchemaUtils.create”方法时,一切都很好,但是,当然,当我用一些新闻栏重新启动服务器时,没有创建栏
你知道如何解决这个问题吗?我做错了什么?谢谢