hey <@U053JQ6TZR9>, I think I found another castin...
# exposed
m
hey @Chantal Loncle, I think I found another casting bug in 0.53, or maybe it wasn't fixed yet, will investigate a bit more doing a eager load on a reference
load
that looks like this
Copy code
val theRef by AnotherEntity referrersOn AnotherEntityTable.someID
end ups here with a
distinctRefIds
that is of type
DaoEntityID
but the column type from
refColumn
is
uuid
(in this case a custom kind of UUID, but that doesn't seem to be the problem) and as expected, the casting crashes
Copy code
class org.jetbrains.exposed.dao.DaoEntityID cannot be cast to class the.custom.ID
c
Thanks for letting us know @minivac. To confirm, this casting issue is with the same underlying type reference as before? Meaning the column
AnotherEntityTable.someID
is defined something like:
Copy code
val someID: Column<UUID> = uuid("some_id").references(OtherTable.id)
Or is the column defined as:
Copy code
val someID: Column<EntityID<UUID>> = reference("some_id", OtherTable)
m
it's registered like this
Copy code
object AnotherTable : (...)
        val mainTableID = registerColumn<UUID>("main_table_id", UUIDColumnType()).references(MainTable.id)
}
it's essentially a 1-N, my main table in this case is
Project
and the N table is
Member
, and member has a row
val projectID = registerColumn<UUID>(...).references(ProjectTable.id)
so later, in the
MemberEntity
I use
val project by ProjectEntity referencedOn MemberTable.projectID
, and that works if accessing it normally as a reference but crashes with the
load
function
the IDs are UUIDs everywhere, the column type is a custom one that wraps the UUID for type safety, but that's not related to the bug, it would crash anyway since a
DaoEntityID
is not castable to a
UUID
or whatever the actual type of the column is
also, the column in the main table (
Project
) is defined like your second option
Copy code
class ProjectTable: IdTable<UUID> {
   override val id: Column<EntityID<UUID>> = (...).entityId()
}
Copy code
class MemberTable: IdTable<UUID> {
  val projectID =registerColumn("project_id", ...)
        .references(ProjectTable.id)
}
c
Yes, the bug is not because of any customizations. It is happening because
Column.references()
is being used to define the referencing column instead of
reference()
. So the parent is of type
EntityID<UUID>
as expected, but the child column is then of type
UUID
, and the DAO referential logic was set up to expect that referencing columns would always be storing the same type. I'm able to get the exception when eager loading
referrersOn
, as you mentioned in your first message, and a fix is done. But I'm not getting any issue with
referencedOn
like in your later messages. Was that a typo? You previously reported the issue with
referencedOn
and we pushed fixes for it (both lazy and eager loaded).
m
just checked, it is
referrersOn
, it was a typo
c
Thanks for confirming. This fix will also cover
backReferencedOn
in the event you end up using it too.