I'm trying to use Kotlin Exposed on Jetbrains Compose for Desktop, but I keep getting an error when ...
a
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.
t
What Exposed version do you use?
r
@Amaan you fixed this?
a
No, not yet. I'm using Exposed version 0.35.1 and Compose version 1.0.0-alpha4-build362 and sqlite-jdbc version 3.36.0.3
lazy load an external entity
t
@Amaan, if you need to keep references between transactions please try to set
keepLoadedReferencesOutOfTransaction = true
https://github.com/JetBrains/Exposed/blob/master/docs/ChangeLog.md#0351
b
@tapac
the code does not load external entities in a transaction.
t
So how you want to get entities loaded from DB ourside the transaction?
a
I'm not sure what you mean or if you're asking me that question, but it seems like you have to set the
eagerLoading
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.
t
Indeed, before 0.35.1 references where stored in transaction related cache. ea Now your can set
keepLoadedReferencesOutOfTransaction
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
a
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.
284 Views