Morphia use for Scala
Question
Is it possible to use Morphia in Scala?
Are there any other lightweight ORMs for MongoDB that support scala?
La solution
Morphia is just a persistence layer based on mongo-java-driver that uses annotation in a JPA-style for object mapping. It should perfectly work with Scala.
Among the "native" Scala drivers (worth to mention that all of them are also based on mongo-java-driver), Rogue (developed by Foursquare) is the closest ideologically to Morphia (though it doesn't use annotations, which aren't considered to be Scala-idiomatic).
Autres conseils
Check out Salat:
https://github.com/novus/salat
Salat uses pickled Scala signatures to serialize and deserialize case classes.
I prefer "Mongo Scala Driver":
Morphia is probably much more approachable and has a (much) smoother learning curve, but it's crucial to realize that the static type-safety and auto-completion support Rogue gives you when querying is really one level above Morphia—Morphia is only runtime safe, which they also admit right the beginning of the README.
Compare:
val checkin: Option[Checkin] =
Checkin where (_.venueid eqs id)
and (_.userid eqs mayor.id)
and (_.cheat eqs false)
and (_._id after sixtyDaysAgo)
limit(1).get()
vs
Employee scottsBoss =
ds.find(Employee.class).filter("underlings", scottsKey).get();
If you change any of the field names or query values to be incorrect, you'll get an immediate typing error, whereas Morphia will only throw an exception at runtime.
See http://engineering.foursquare.com/2011/01/21/rogue-a-type-safe-scala-dsl-for-querying-mongodb/