# exposed

Luca Piccinelli

04/24/2021, 2:00 PM
@tapac I have this code
Copy code
object 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
    var hero by HeroDao referencedOn BuddyTable.hero

override fun save(entity: Buddy): Int = transaction {
        BuddyTable.insert {
            it[name] =
            it[hero] =
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
Copy code
Detail: Key (id)=(3) already exists.. Statement(s): INSERT INTO toh.buddy (hero_id, "name") VALUES (?, ?) 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 3


04/24/2021, 2:02 PM
It's known issue ( the fix will be available today or tomorrow
👍 1
🙏 1

Luca Piccinelli

04/24/2021, 2:03 PM
ah ok... looking at the code I thought it should already work
there exist a workaround to use autoincrement with postgres?
sorry, in my case it was my fault, not a bug. In the test I was assigning the ids manually (then the sequence didn't get incremented), while in the repository I was using the sequence.