Luca Piccinelli
04/24/2021, 2:00 PMobject BuddyTable: IdTable<Int>("toh.buddy"){
override val id = integer("id").autoIncrement("toh.buddy_seq_id").entityId()
val name = varchar("name", 50)
val hero = reference("hero_id", HeroTable)
}
class BuddyDao(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<BuddyDao>(BuddyTable)
var name by BuddyTable.name
var hero by HeroDao referencedOn BuddyTable.hero
}
override fun save(entity: Buddy): Int = transaction {
BuddyTable.insert {
it[name] = entity.name
it[hero] = entity.hero.id
}[BuddyTable.id].value
}
In postgres it looks like it is not using the sequence to generate the new id (also if i don't override the id field)
Prefixing or not with the schema "toh" doesn't change.
The error is
Detail: Key (id)=(3) already exists.. Statement(s): INSERT INTO toh.buddy (hero_id, "name") VALUES (?, ?)
org.jetbrains.exposed.exceptions.ExposedSQLException: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "buddy_pkey"
Detail: Key (id)=(3) already exists.
It does 3 transaction attempts with ids 1, 2 and 3tapac
04/24/2021, 2:02 PMLuca Piccinelli
04/24/2021, 2:03 PM