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 is not in record set #1548

Closed
alogvinov-forter opened this issue Jul 8, 2022 · 2 comments · Fixed by #1731
Closed

id is not in record set #1548

alogvinov-forter opened this issue Jul 8, 2022 · 2 comments · Fixed by #1731
Assignees

Comments

@alogvinov-forter
Copy link

Hi, I'm currently evaluating Exposed as an ORM for for a simple web application. Running the test below on Java 17, Exposed version 0.38.2 and H2 in-memory db.

Table and entity definitions:

object Requests : IdTable<String>() {
    val reqId: Column<String> = varchar("reqId", 256)
    override val primaryKey = PrimaryKey(reqId)
    override val id: Column<EntityID<String>> = reqId.entityId()
}
class RequestEntity(id: EntityID<String>) : Entity<String>(id) {
    companion object : EntityClass<String, RequestEntity>(Requests)
    var reqId by Requests.reqId
}

The following test fails with Requests.reqId is not in record set:

@Test
fun entityTest() {
    transaction(database) {
        addLogger(StdOutSqlLogger)

        SchemaUtils.create(Requests)

        RequestEntity.new {
            reqId = "123"
        }

        val requests = RequestEntity.all().count()
        println("Requests: $requests")
    }
}

Looking into debug, I can see that the column comparison fails because of the type mismatch - EntityIDColumnType vs VarCharColumnType.

If I change the entity mapping as such

    ...
    var reqId by Requests.id

and change the insert accordingly, the test passes.

Please advise if there's something I'm missing. (Also, it would be nice to include an example with non-int id in docs.)

@alogvinov-forter alogvinov-forter changed the title is not in record set id is not in record set Jul 8, 2022
@AlexeySoshin
Copy link
Contributor

@alogvinov-forter , I'm curious, what is your use case for String as EntityId?
Is it due to historical reasons?

@alogvinov-forter
Copy link
Author

@AlexeySoshin sorry, I've just noticed your comment. Not really, this is by design. Request id is an internal UUID, which is a formatted timestamp augmented with some random suffix and name of the sub system that generated it.

A way to workaround this issue would be to introduce an auto-increment id column which would be there just for the technical purposes, but I'd prefer not to do this as request id is unique, and it's a primary key.

@joc-a joc-a self-assigned this Apr 24, 2023
@joc-a joc-a linked a pull request Apr 25, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants