postgresql Jetbrains暴露ORM重复列异常

8aqjt8rx  于 2023-08-04  发布在  PostgreSQL
关注(0)|答案(1)|浏览(119)

我正在尝试暴露的ORM,但我得到了以下错误,我可怜的眼睛找不到原因:
线程“main”org.jetbrains.exposed.exceptions.DuplicateColumnException异常:表“Venues”中的列名“name”重复

object Organizations: IntIdTable() {
    val name: Column<String> = varchar("name", 255)
    val email: Column<String> = varchar("email", 255)
}

object Venues: IntIdTable() {
    val name: Column<String> = varchar("name", 255)
    val address: Column<String> = varchar("address", 255)
    val organizationId = reference("organizationId", Organizations)
}

object Spaces: IntIdTable() {
    val name: Column<String> = varchar("name", 255)
    val capacity: Column<Int> = integer("capacity")
    val type: Column<Int> = integer("type")
    val venue = reference("venueId", Venues)
}

object DatabaseFactory {
    private val appConfig = ConfigFactory.load()
    private val dbUrl = appConfig.getString("db.jdbcUrl")
    private val dbUser = appConfig.getString("db.dbUser")
    private val dbPassword = appConfig.getString("db.dbPassword")

    fun init() {
        val database = Database.connect(hikari())
        transaction(database) {
            // create tables if missing
            SchemaUtils.create(
                Organizations,
                Venues,
                Spaces
            )
        }
    }

    private fun hikari(): HikariDataSource {
        val config = HikariConfig()
        config.driverClassName = "org.postgresql.Driver"
        config.jdbcUrl = dbUrl
        config.username = dbUser
        config.password = dbPassword
        config.maximumPoolSize = 3
        config.isAutoCommit = false
        config.transactionIsolation = "TRANSACTION_REPEATABLE_READ"
        config.validate()
        return HikariDataSource(config)
    }
}

字符串

vqlkdk9b

vqlkdk9b1#

必须在每个对象定义处传递表的名称

object Organizations: IntIdTable("organizations") {
    val name: Column<String> = varchar("name", 255)
    val email: Column<String> = varchar("email", 255)
}

object Venues: IntIdTable("venues") {
    val name: Column<String> = varchar("name", 255)
    val address: Column<String> = varchar("address", 255)
    val organizationId = reference("organizationId", Organizations)
}

object Spaces: IntIdTable("spaces") {
    val name: Column<String> = varchar("name", 255)
    val capacity: Column<Int> = integer("capacity")
    val type: Column<Int> = integer("type")
    val venue = reference("venueId", Venues)
}

字符串

相关问题