How can Slick (using 2.1) be set up so that it uses the same transaction manager associated to a Spring configuration?
More context: We have an app that relies on Slick for its db work, and uses a library (Activiti) whose transaction management is provided by Spring. We wrap calls to that lib around Spring transactions like shown below, and we'd like that whenever a transaction fails on Activiti's side, then the queries issued by our Slick calls get rolled back as well.
def withSpringTransaction[T](f: TransactionStatus => T)(implicit transactionTemplate: TransactionTemplate) =
transactionTemplate.execute(new TransactionCallback[T] {
protected def doInTransaction(status: TransactionStatus) = f(status)
})
withSpringTransaction { transactionStatus =>
db.withTransaction { session =>
// Activiti API calls
// Slick API calls
}
}
I know we could call both transactionStatus.setRollbackOnly()
and session.rollBack()
in the preceding code if something goes bad, but our problem lies in more complex scenarios where Activiti calls some listener elsewhere where there is no access to the session declared in this scope.