Hey, maybe someone in here can help me wrap my hea...
# exposed
f
Hey, maybe someone in here can help me wrap my head around an issue I am having with Exposed/h2. I used a
transaction
to obtain an entry from the database, like so:
Copy code
val testBook = transaction { Book.findById(1)!! }
Now, immediately after that line, I tried
Copy code
<http://log.info|log.info>("Book title: ${testBook.title}")
…which gave me an
org.h2.jdbc.JdbcSQLException: The object is already closed [90007-196]
exception. From what I gathered, this is intended behavior because I am not within the transaction anymore. But in order to avoid this error: Would I need to find a place from which I can basically wrap my entire application within one giant transaction for the entire life cycle of the app? That seems very wrong to me. Would I need to create copies of the database objects within a transaction and then only use the copies afterwards? Why would I then want to create the corresponding DAOs if I cannot use them like other objects? Or is there some magic bit of code that I just don’t know about yet?