Kotlin Exposed ORM - id not in record set

Viewed 1447

New to Kotlin Exposed and trying to store data using IdTable and getting errror 'id is not in record set.' Below is the code using

object GeoLocationModel : IdTable<Long>("geolocation_pos") {
    val code = long("code").primaryKey()
    val createdAt = datetime("created_at").clientDefault { currentUtc() }
    val updatedAt = datetime("updated_at").nullable()
    val createdBy = varchar("created_by", 255).clientDefault { authenticatedUser() }
    val updatedBy = varchar("updated_by", 255).nullable()
    val uuid = uuid("uuid").autoGenerate().uniqueIndex()
    val latitude: Column<Double> = double("latitude")
    val longitude: Column<Double> = double("longitude")
    val pincode: Column<Long> = long("pincode")
    override val id: Column<EntityID<Long>> =  code.entityId()
}

object GeoLocationModel : IdTable<Long>("geolocation_pos") {
    val code = long("code").primaryKey()
    val createdAt = datetime("created_at").clientDefault { currentUtc() }
    val updatedAt = datetime("updated_at").nullable()
    val createdBy = varchar("created_by", 255).clientDefault { authenticatedUser() }
    val updatedBy = varchar("updated_by", 255).nullable()
    val uuid = uuid("uuid").autoGenerate().uniqueIndex()
    val latitude: Column<Double> = double("latitude")
    val longitude: Column<Double> = double("longitude")
    val pincode: Column<Long> = long("pincode")
    override val id: Column<EntityID<Long>> =  code.entityId()
}

Insertion of data for **geolocation_pos** table

 val geolocationId = GeoLocationModel.insert {
                it[code] = nextSequenceVal()
                it[latitude] = 28.550667
                it[longitude] = 77.268952
                it[pincode] = xxxxxx
            } get GeoLocationModel.id 

MySQL database is not able to save throws an error stating

java.lang.IllegalStateException: com.xxxx.xxxx.xxxx.xxx.GeoLocationModel.code is not in record set
    at org.jetbrains.exposed.sql.ResultRow.getRaw(ResultRow.kt:53) ~[exposed-core-0.21.1.jar:na]
    at org.jetbrains.exposed.sql.ResultRow.get(ResultRow.kt:18) ~[exposed-core-0.21.1.jar:na]
    at org.jetbrains.exposed.sql.statements.InsertStatement.get(InsertStatement.kt:20) ~[exposed-core-0.21.1.jar:na]

Generated SQL

INSERT INTO geolocation_pos (code, created_at, created_by, latitude, longitude, pincode, updated_at, updated_by, uuid) VALUES (106, 'xxxxxxx', 'xxx', 28.550667, 77.268952, xxxxx, NULL, NULL, 'dd6aaf69-5324-4fac-9271-5c099957e06b')

Please can anyone help me resolving the issue.

0 Answers
Related