Friday, March 13, 2009

ScalaJPA hits 1.0

I've been working on packaging up some of the Scala <-> JPA boilerplate in use for the Lift JPA Demo into a small project called ScalaJPA. After some work on documentation and bringing it up to Lift 1.0 goodness, you can find the project here:

Scaladoc is here:

If you're using Maven, simply drop this dependency into your pom.xml:


Just to give you an idea of how easy it is to use, here's how we would define a per-request EntityManager in Lift:


import org.scala_libs.scalajpa.{LocalEM,RequestVarEM}

object Model extends LocalEM("MyEMName") with RequestVarEM

The Model object will then act as a ScalaEntityManager that uses a new per-request EM for its operations. We can use it in our code like

val author = new Author("Kurt Vonnegut")
val book = new Book("Cat's Cradle", author)

In addition to the RequestVarEM, there are classes to handle a ThreadLocal EM as well as plain old factory classes that will let you set up and close your own ScalaEntityManagers. Check out the Lift JPA Demo site for more example code: