Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

id not in record set #820

Closed
nyenugula-zealsoft opened this issue Mar 4, 2020 · 7 comments
Closed

id not in record set #820

nyenugula-zealsoft opened this issue Mar 4, 2020 · 7 comments
Assignees
Labels

Comments

@nyenugula-zealsoft
Copy link

nyenugula-zealsoft commented Mar 4, 2020

New to Kotlin Exposed and trying to store data using IdTable and getting error '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()
}

class GeoLocationEnity(id: EntityID<Long>) : Entity<Long>(id) {
    companion object : EntityClass<Long, GeoLocationEnity>(GeoLocationModel)

    var code by GeoLocationModel.code
    var createdBy by GeoLocationModel.createdBy
    var updatedBy by GeoLocationModel.updatedBy
    var createdAt by GeoLocationModel.createdAt
    var updatedAt by GeoLocationModel.updatedAt
    var uuid by GeoLocationModel.uuid
    var latitude by GeoLocationModel.latitude
    var longitude by GeoLocationModel.longitude
    var pincode by GeoLocationModel.pincode
}

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 Query

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.

@Tapac
Copy link
Contributor

Tapac commented Mar 14, 2020

fixed in master

@Tapac Tapac closed this as completed Mar 14, 2020
@jontysponselee
Copy link

jontysponselee commented Jun 15, 2020

Is there another way to access the inserted ID or should I wait for a new release or should I use an older version of exposed?

@Tapac
Copy link
Contributor

Tapac commented Jun 15, 2020

It should be fixed since 0.23.1

@jontysponselee
Copy link

I have the following code in version 0.25.1 and it doesn't work.

// Build.gradle $exposed_version = 0.25.1
implementation "org.jetbrains.exposed:exposed-core:$exposed_version"
implementation "org.jetbrains.exposed:exposed-dao:$exposed_version"
implementation "org.jetbrains.exposed:exposed-jdbc:$exposed_version"
implementation "org.jetbrains.exposed:exposed-jodatime:$exposed_version"
try {
    transaction {
        val userID = UserDAO.insert {
            it[username] = user.username!!
            it[email] = user.email!!
            it[password] = user.password!!
            it[verified] = user.verified!!
            it[birthday] = user.birthday!!
        } get UserDAO.id

    // temp fix
    // val userID = UserDAO.select { UserDAO.email eq (user.email!!) }.firstOrNull()?.get(UserDAO.id)
    user.id = userID
    }
} catch (e: Exception) {
    // throws java.lang.IllegalStateException: ....dao.UserDAO."ID" is not in record set
    throw Exception("User could not be inserted.")
}

object UserDAO : Table("user") {
    val id: Column<Int> = integer("\"ID\"")
    val username: Column<String> = varchar("username", 255)
    val email: Column<String> = varchar("email", 255).uniqueIndex()
    val password: Column<String> = varchar("password", 255)
    val verified: Column<Boolean> = bool("verified")
    val birthday: Column<DateTime> = date("birthday")

    override val primaryKey = PrimaryKey(id)
}

@Tapac
Copy link
Contributor

Tapac commented Jun 16, 2020

@infinityart , sorry but why do you expect to get id from a recordset where you don't set it and when id is not auto-generated column?

@jontysponselee
Copy link

@Tapac actually, the column "id" is specified as an auto-incremented column in the database. I use pgsql, the table type is "serial" and it uses the sequence "user_ID_seq". I have added .autoIncrement("user_ID_seq") after integer("\"ID\"") in the UserDAO and I still get the same exception

@Tapac
Copy link
Contributor

Tapac commented Jun 24, 2020

@infinityart , could you try to remove quotes from id column name? "\"ID\" -> "ID". WIll it work with your table mapping?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants