Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Lift JTA Transaction API

The semantics are the same as used in the EJB spec. E.g. Required, RequiresNew, Mandatory, Supports, Never. All these are exposed as monadic objects and high-order functions in the TransactionContext object.

The implementation is hooked into the Lift’s JPA implementation.
Check the ScalaDoc (or the source) for the documentation on usage, semantics etc.

There are two versions of the API, one monadic and one using high-order functions.

Monadic API

 for {
   ctx <- TransactionContext.Required
   entity <- updatedEntities
   if !ctx.isRollbackOnly
 } {
   // transactional stuff
val users = for {
   ctx <- TransactionContext.RequiresNew
   name <- userNames
 } yield {
   // transactional stuff
   val query = ctx.getEntityManager.createNamedQuery("findUserByName")
   query.setParameter("userName", name)

High-order functions API

TransactionContext.withTxRequired {
    ... // REQUIRED semantics 

  TransactionContext.withTxRequiresNew {
    ... // REQUIRES_NEW semantics


The configuration is done in the persistence.xml file + the jta.properties. Sample configuration files can be found in the src/main/resources directory.
Here are the essential configuration options in the JPA persistence.xml file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  <persistence-unit name="LiftPersistenceUnit" transaction-type="JTA">


      <property name="hibernate.transaction.manager_lookup_class"
                value="net.liftweb.transaction.hibernate.LiftTransactionManagerLookup" />


Currently it is hard-coded to use the Atomikos Transaction library and the Hibernate JPA implementation.
This will have to be configurable + some other options as well. See the TODOs in the code.