I've been using iBATIS for years and have been very happy with it. iBATIS is very good about letting one write their own SQL while handling the mundane work of mapping data to/from the objects/database. I would love a Scala specific library that does the same type of mappings that iBATIS does. I figure a Scala specific tool would
I've seen a bunch of stuff on the web talking about ORMs for Java and Scala, but I haven't seen anything like iBATIS for Scala.
Does anybody know of a tool like this in Scala?
Times have changed. There is now a MyBatis Scala project which is much more idiomatic to Scala.
http://mybatis.github.io/scala/
I've evaluated it, and it looked like a lot less hassle than any of the other ORM or Scala oriented persistence libraries.
The links on their project page are currently broken, but you can get to the GitHub page here: https://github.com/mybatis/scala
They have various samples under "mybatis-scala-samples". This DAO / CRUD example is a particularly nice example: ItemDAO.scala
Why not just carry on using iBatis? It's Java, after all (and hence can be used from Scala). I still use Spring JDBC as my DAO layer.
As for the scala-specifics; you could add the @BeanProperty
annotation to generate getters/setters and then declare a method to guard for null
:
@BeanProperty var injectedXyz : String
def xyz : Option[String] = Option(injectedXyz)
Admittedly this is not great (i.e. requires extra boilerplate). But I have not seen anything that looks like a widely-used scala DAO layer (for SQL)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With