I'm trying to use Kotlin Exposed on Jetbrains Comp...
# exposed
I'm trying to use Kotlin Exposed on Jetbrains Compose for Desktop, but I keep getting an error when I try to reference a many to one relationship outside of the transaction. Essentially, I have an Event class and a Section class. Events have multiple sections. When I get an event via the transaction and then try to access the sections variable, I get a null pointer exception. I've attached my code below as well as the error message I got. I can't create composables inside of transaction functions which is why I have to get the list of events out of the transactions scope.
What Exposed version do you use?
@Amaan you fixed this?
No, not yet. I'm using Exposed version 0.35.1 and Compose version 1.0.0-alpha4-build362 and sqlite-jdbc version
lazy load an external entity
@Amaan, if you need to keep references between transactions please try to set
keepLoadedReferencesOutOfTransaction = true
the code does not load external entities in a transaction.
So how you want to get entities loaded from DB ourside the transaction?
I'm not sure what you mean or if you're asking me that question, but it seems like you have to set the
param to true so you can access the string once you get the query from the transaction, but that doesn't seem possible when setting references.
Indeed, before 0.35.1 references where stored in transaction related cache. ea Now your can set
and the references will be bound to the entity, but you still need to load them. Also,
eagerLoading = true
available on text columns not on references
Interesting, so the
keepLoadedReferencesOutOfTransaction = true
does let me get the pointer to the sections and get the count of sections since it's a LazySizedCollection, but I can't actually get the values of the sections that belong to the event. I have updated code that I included below.