title: How to enforce creating new transaction in Lift Mapper?
body: <p>We are using Lift + Mapper (version 2.4) in our project. We as well are using transaction-per-request pattern <code>S.addAround(DB.buildLoanWrapper())</code>. </p>
  
  <p>In one of our requests we need to have nested transaction which we found to be problematic. We found that one of possible 'hacks' is to start transaction in a separate thread (like in example below) because <code>DB</code> object uses <code>ThreadLocal</code> to manage current connection and transaction state info.</p>
  
  <p>Is there any implementation that is better (more safer and without multi-threading) than the one bellow?</p>
  
  <pre><code>  import net.liftweb.db.{DefaultConnectionIdentifier, DB}
    import akka.dispatch.Future
  
    /**
     * Will create a new transaction if none is in progress and commit it upon completion or rollback on exceptions.
     * If a transaction already exists, it has no effect, the block will execute in the context
     * of the existing transaction. The commit/rollback is handled in this case by the parent transaction block.
     */
    def inTransaction[T](f: ⇒ T): T = DB.use(DefaultConnectionIdentifier)(conn ⇒ f)
  
    /**
     * Causes a new transaction to begin and commit after the block’s execution,
     * or rollback if an exception occurs. Invoking a transaction always cause a new one to be created,
     * even if called in the context of an existing transaction.
     */
    def transaction[T](f: ⇒ T): T = Future(DB.use(DefaultConnectionIdentifier)(conn ⇒ f)).get
  </code></pre>