hey <@U053JQ6TZR9>, looks like the casting bug I f...
# exposed
m
hey @Chantal Loncle, looks like the casting bug I found last time with UUIDs is also happening when doing eager loading in exposed 0.51.0 eager loading a table with a UUID as primary key
Copy code
val new = ProjectMemberEntity.new {
                ...
                this.userID = userID
            }
            .load(ProjectMemberEntity::user) // <- crashes
Copy code
class x.z.y.UserID cannot be cast to class org.jetbrains.exposed.dao.id.EntityID (x.y.z.UserID and org.jetbrains.exposed.dao.id.EntityID are in unnamed module of loader 'app')
But accessing it normally works fine
Copy code
val new = ProjectMemberEntity.new {
                ...
                this.userID = userID
            }
            new.user // this is fine, it resolves the user correctly
Seems like is exactly the same bug, some incorrect use of the column type.
the entity is just a very basic one
Copy code
class ProjectMemberEntity(...) {
    var userID by ProjectMemberTable.userID
    val user by UserEntity referencedOn ProjectMemberTable.userID
    val project by ProjectEntity referencedOn ProjectMemberTable.projectID
}
c
Hi @minivac I wasn't able to reproduce the exception above on version 0.51.1. Could you please look at the table/entity mappings below and confirm where the difference is so I can look into it more? Thanks!
Copy code
object UserTable : UUIDTable("user")

class UserEntity(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<UserEntity>(UserTable)
}

object ProjectMemberTable : UUIDTable("project_member") {
    val userID = reference("user_id", UserTable)
}

class ProjectMemberEntity(id: EntityID<UUID>) : UUIDEntity(id) {
    var userID by ProjectMemberTable.userID
    val user by UserEntity referencedOn ProjectMemberTable.userID

    companion object : UUIDEntityClass<ProjectMemberEntity>(ProjectMemberTable)
}

transaction {
    try {
        SchemaUtils.create(UserTable, ProjectMemberTable)

        val user1 = UserEntity.new { }

        val newPM = ProjectMemberEntity.new {
            userID = user1.id
        }.load(ProjectMemberEntity::user)

        assertEquals(user1, newPM.user)
    } finally {
        SchemaUtils.drop(UserTable, ProjectMemberTable)
    }
}
m
sure, I'll try to isolate it again
Copy code
object ProjectTable : UUIDTable("tmp_project")

class ProjectEntity(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<ProjectEntity>(ProjectTable)

    val members by ProjectMemberEntity referrersOn ProjectMemberTable.projectId
}

object ProjectMemberTable : UUIDTable("tmp_project_member") {
    val projectId = registerColumn("project_id", UUIDColumnType())
        .references(ProjectTable.id)
}

class ProjectMemberEntity(id: EntityID<UUID>) : UUIDEntity(id) {
    companion object : UUIDEntityClass<ProjectMemberEntity>(ProjectMemberTable)

    var projectId by ProjectMemberTable.projectId
}

class Bug : BaseIntegrationTest() {

    @Test
    fun `eager load bug`() = integrationTest {
        transaction {
            try {
                SchemaUtils.create(ProjectTable, ProjectMemberTable)
                val project = ProjectEntity.new { }
                ProjectMemberEntity.new {
                    projectId = project.id.value
                }
                val b = ProjectEntity.all().first().load(
                    ProjectEntity::members
                ) // Crash here
                println(b.members) 
            } finally {
                transaction {
                    SchemaUtils.drop(ProjectTable, ProjectMemberTable)
                }
            }
        }
    }
}
it's a copy paste of my tests case, but I think should be able to adapt pretty easy, didn't know about the
Schemautils.create/drop
, very useful 👌
the crash is slightly different, now it's a
DaoEntity
Copy code
class org.jetbrains.exposed.dao.DaoEntityID cannot be cast to class java.util.UUID (org.jetbrains.exposed.dao.DaoEntityID is in unnamed module of loader 'app'; java.util.UUID is in module java.base of loader 'bootstrap')
0.51.1
I am on 0.51.0, let me bump just to make sure
same on 0.51.1
c
Thanks for putting this together so quickly. Here's the YT issue to track: EXPOSED-402. A fix will be pushed soon.
🙌 1