I am going to write a Scala command-line application that uses MySQL database. I have been searching around for ORMs, and am getting trouble finding one which works well.

The Lift ORM looks nice, but I am unsure it may be decoupled in the entire Lift web framework. ActiveObjects also looks OK, however the author states that it could not fully trust Scala.

I am not visiting Scala from Java, so I'm not sure all of the options. Has anybody used an ORM with Scala, and when so, what have you use and just how well made it happen work?

You will find the key reason why JPA-oriented frameworks (Hibernate, for example) don't squeeze into idiomatic Scala programs stylishly:

  • you will find no nested annotations as states the Scala 2.8 Preview -- which means you can't use annotations as mapping metadata for complex programs (the easiest ones frequently use @JoinTable -> @JoinColumn)
  • incongruencies between Scala and Java collections make designers convert collections you will find also cases when it's impossible to map Scala collections to associations without applying complex connects from the underlying framework (Hibernate's PersistentCollections, for instance)
  • some common features, for example domain model validation, require JavaBeans conventions on persistent classes -- these stuff is less than "Scala way" to do things
  • obviously, the interop problems (like Raw Types or proxies) introduce another degree of issues that can't be walked around easily.

You will find more reasons, I am sure. This is exactly why we now have began the Circumflex ORM project. This pure-Scala ORM tries it is best to get rid of the bad dreams of classic Java ORMs. Particularly, you define your organizations in virtually way you'd do that with classic DDL claims:

class User stretches Record[User] title = "title".TEXT.NOT_NULL

  val admin = "admin".BOOLEAN.NOT_NULL.DEFAULT('false')



object User stretches Table[User] title LIKE n).list



// example with foreign secrets:

class Account stretches Record[Account] Remove(CASCADE)

  val amount = "amount".Number(10,2).NOT_NULL



object Account stretches Table[Account]

As you can tell, these terms are a little more verbose, than classic JPA POJOs. However you will find several concepts which are put together together:

  • the particular DDL for producing schema (it is simple to add indexes, foreign secrets along with other stuff within the same DSL-like fashion)
  • all queries could be put together within that "table object" rather than being scattered around in DAO the queries are very flexible, you are able to store query objects, predicates, forecasts, subqueries and relation aliases in variables to help you reuse them, as well as make batch update procedures from existing queries (place-choose for instance)
  • transparent navigation between associations (one-to-one, many-to-one, one-to-many and several-to-many-through-intermediate-relation) could be accomplished either by lazy or by eager fetching methods in the two cases the associations are in place on the top from the foreign secrets of underlying relations
  • validation is negligence framework
  • there's additionally a Maven2 wordpress plugin that enables producing schema and posting initial data from handy XML formatted files.

The only real things Circumflex ORM lacks are:

  • multi-column primary secrets (although you'll be able to create multi-column foreign secrets backed by multi-column unique constraints, but it's just for data integrity)
  • full-fledged documentation (although we're positively focusing on it)
  • success tales of ten-billion-dollar production systems which have Circumflex ORM as it is core technology.

P.S. I really hope this publish won't be considered an advert. It is not so, really -- I had been attempting to be as objective as you possibly can.