I find SORM very Interesting and promising but I cant find a way to Integrate It with play any guides?
3 Answers
- Install Play >= 2.1.0.
- Generate a project using Play's guides
Add appropriate SORM's and chosen database's dependencies to the generated
project/Build.scala
, e.g.:val appDependencies = Seq( "org.sorm-framework" % "sorm" % "0.3.8", "com.h2database" % "h2" % "1.3.168" )
In the same file make sure that your project depends on the same Scala version, on which SORM depends (for SORM 0.3.8 it's Scala 2.10.1):
val main = play.Project(appName, appVersion, appDependencies).settings( scalaVersion := "2.10.1" )
If you miss that step, you may bump into this issue.
In
app/models/package.scala
place all your case classes and SORM's instance declaration, e.g.:package models case class A( name : String ) case class B( name : String ) import sorm._ object Db extends Instance( entities = Set(Entity[A](), Entity[B]()), url = "jdbc:h2:mem:test" )
Note that there is no requirement to follow these naming and location conventions - e.g., you can put your SORM instances in your controllers or elsewhere if you want.
In
app/controllers/Application.scala
place some controller actions utilizing SORM, e.g.:package controllers import play.api.mvc._ import models._ object Application extends Controller { def index = Action { val user = Db.save(A("test")) Ok(user.id.toString) } }
This will print out a generated id of the saved
A
case class value.Run your server using
play run
orplay start
command.

- 1
- 1

- 42,792
- 11
- 94
- 169
-
Thanks! Any idea how to easily grab the db.default settings from Play? – Eneko Alonso May 06 '13 at 03:36
-
1In case anyone needs it, this answer explains it well: http://stackoverflow.com/questions/9857907/access-play-2-0-configuration-variables-in-application-conf – Eneko Alonso May 13 '13 at 21:07
Play was updated to use a new build file format
Ref : Build.scala is not created in play
You can continue from build.sbt file anymore
ForEx:
libraryDependencies ++= Seq(
jdbc,
cache,
"org.sorm-framework" % "sorm" % "0.3.8",
ws,
specs2 % Test
)
For new usage :
libraryDependencies ++= Seq(
jdbc,
cache,
ws,
"org.sorm-framework" % "sorm" % "0.3.22",
"com.h2database" % "h2" % "1.3.168",
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test
)

- 926
- 9
- 16
-
When giving an answer it is preferable to give [some explanation as to WHY your answer](http://stackoverflow.com/help/how-to-answer) is the one. This is especially true on *very* old questions – Stephen Rauch Feb 21 '17 at 01:37