I'm trying to use the new upsert feature with an e...
# exposed
r
I'm trying to use the new upsert feature with an embedded H2 database, and I'm seeing this error:
org.jetbrains.exposed.exceptions.ExposedSQLException: org.h2.jdbc.JdbcSQLDataException: Data conversion error converting "��&��E��B-\000a�\000b!�";
More info in 🧵
For more information, the table is something like this:
Copy code
object HeaderTable : Table("header") {
    val id = uuid("id").autoGenerate()
    val type = varchar("type", TYPE_SIZE).nullable()
    val isMulti = bool("multi").default(false)
    val created = timestamp("created").defaultExpression(CurrentTimestamp())
    val updated = timestamp("updated").defaultExpression(CurrentTimestamp())
    override val primaryKey = PrimaryKey(id)
}
(the actual table is part of an inheritance hierarchy, but this is effectively what it amounts to) And the
upsert
statement is
Copy code
HeaderTable.upsert {  // <-- The error is pointing at this line
    it[id] = header.id
    it[title] = header.title
    it[created] = header.created
    it[updated] = header.updated
    header.type?.let { ht ->
        it[type] = encodeType(ht.type)
        it[isMulti] = ht.type.isMulti
    }
}
(
created
and
updated
are `java.time.Instant`s, and
encodeType(...)
returns an string with only lowercase ASCII letters)
Also, I'm pretty sure it's an issue with
upsert
. If I change to this, it works fine:
Copy code
if (HeaderTable.findById(header.id) == null) {
    HeaderTable.insert { setup(it, header) }
} else {
    HeaderTable.update(
        { HeaderTable.id eq header.id }
    ) { setup(it, header) }
}
Where
setup
is
Copy code
fun HeaderTable.setup(it: UpdateBuilder<*>, header: Header) {
    it[id] = header.id
    it[title] = header.title
    it[created] = header.created
    it[updated] = header.updated
    header.type?.let { ht ->
        it[type] = encodeType(ht.type)
        it[isMulti] = ht.type.isMulti
    }
}
I went ahead and created an issue for it
e
Hey @Ruckus, thanks for the report! @Chantal Loncle, could you please take a look?
👍 1
120 Views