5
votes

I'm trying to use Sorm into a play framework project. I'm using the 2.1 version which uses Scala 2.10. The problem is that my classes are not recognized by Sorm, I get a ClassNotFoundException

Here is what I used:

package models

case class User(val name: String)

object Db extends Instance (
  entities = Set(Entity[User]()),
  url = "jdbc:h2:mem:test"
)

In my controller:

import models.{Db,User}

object Application extends Controller {
  def index = Action {
    Db.save(User("test")) // Error at this line
    Ok("saved")
  }
}

And the exception:

play.api.Application$$anon$1: Execution exception[[ClassNotFoundException: models.User]]
    at play.api.Application$class.handleError(Application.scala:279) ~[play_2.10.jar:2.1-RC1]
    at play.api.DefaultApplication.handleError(Application.scala:373) [play_2.10.jar:2.1-RC1]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$10$$anonfun$apply$27.apply(PlayDefaultUpstreamHandler.scala:296) [play_2.10.jar:2.1-RC1]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$10$$anonfun$apply$27.apply(PlayDefaultUpstreamHandler.scala:294) [play_2.10.jar:2.1-RC1]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:110) [play_2.10.jar:2.1-RC1]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:110) [play_2.10.jar:2.1-RC1]
Caused by: java.lang.ClassNotFoundException: models.User
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366) ~[na:1.7.0_09]
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355) ~[na:1.7.0_09]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.7.0_09]
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354) ~[na:1.7.0_09]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423) ~[na:1.7.0_09]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ~[na:1.7.0_09]

Any idea how I can make this work ?

1
Okay. I've digged around with Play 2.1-RC1 a bit. It seems there are conflicts between Play's auto-recompilation and SORM's dependency on reflection. I'm not an expert on Play, but I'm sure there must be ways to work around this. We'll try to address the issue in the comming releases, but as for now as sad as it is consider the official status of Play + SORM incompatible. If however somebody finds a workaround, posting it will be much appreciated.Nikita Volkov
Thanks for having looked into it. I will keep an eye on your next releases ;)vdebergue

1 Answers

2
votes

This was an incompatibility issue, which is now fixed since release 0.3.7. Cheers!