https://kotlinlang.org logo
#exposed
Title
# exposed
t

Tristan Blakers

12/02/2020, 11:12 PM
is there a sample project available which combines exposed with spring, webflux, and coroutines?
once things get complicated, e.g. trying to do one transaction across multiple repos, I tend to bump into various exceptions that seem to be caused by the transaction being bound to a ThreadLocal rather than a coroutine context...
w

waltermcq

12/02/2020, 11:24 PM
you may want to try the #spring channel, and also #coroutines
👍 1
j

Joel

12/03/2020, 5:18 AM
@Tristan Blakers that's my tooling. Basically use
newSuspendedTransaction
instead of
transaction
in a coroutine context.
t

Tristan Blakers

12/03/2020, 5:28 AM
Thanks for replying! I tried using newSuspendedTransaction but ran into the same issues. Reading through the source code, it's not clear to me how this could work with Spring, as currently implemented
reason being that in the SpringTransactionManager provided by Exposed, it ultimately calls
Copy code
override fun currentOrNull(): Transaction? = TransactionSynchronizationManager.getResource(this) as Transaction?
which calls into Spring's TransactionSynchronizationManager, which stores the current transaction state in a Threadlocal
j

Joel

12/03/2020, 8:07 PM
I see. I only use the transaction manager in blocking contexts. It should still be able to open a transaction on the thread in which the function is executed, but any suspend points within that function may have issues.
@Tristan Blakers what I've done as a general solution (and to get around the default-db-is-the-last-one issue) is injecting a
Database
connection that wraps my Hikari datapool, and then call Exposed natively from there.
We also use Axon Framework for CQRS and the SpringTransactionManager plays really well with that.
4 Views