[ClassCastException: models.Profile cannot be cast to models.Profile]
scan opened this issue · 5 comments
This one really puzzles me.
This is my code:
package models
import play.api.Play.current
import java.util.{Date}
import com.novus.salat._
import com.mongodb.casbah.Imports._
import se.radley.plugin.mongodb._
import se.radley.plugin.mongodb.salat._
case class Profile(id: String,
displayName: Option[String] = None,
public: Boolean = false,
nsfw: Boolean = false,
created: Date = new Date,
meta: Map[String, String] = Map.empty)
object Profiles extends SalatDAO[Profile, String](collection = getCollection("profiles")) {
def get(id: String): Profile = findOneByID(id).getOrElse {
val prof = Profile(id)
insert(prof)
prof
}
def allPublic = find(MongoDBObject("public" -> true))
}
This occurs after an automatic recompiling. If I stop the server entirely, do a clean
in the code, then restart, it works - once. After a second re-build, I get this error again.
This is the full exception:
play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[ClassCastException: models.Profile cannot be cast to models.Profile]]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:134) [play_2.9.1.jar:2.1-SNAPSHOT]
at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:115) [play_2.9.1.jar:2.1-SNAPSHOT]
at akka.actor.Actor$class.apply(Actor.scala:290) [akka-actor-2.0.jar:2.0]
at play.core.ActionInvoker.apply(Invoker.scala:113) [play_2.9.1.jar:2.1-SNAPSHOT]
at akka.actor.ActorCell.invoke(ActorCell.scala:617) [akka-actor-2.0.jar:2.0]
at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:179) [akka-actor-2.0.jar:2.0]
Caused by: java.lang.ClassCastException: models.Profile cannot be cast to models.Profile
at models.Profiles$.get(Profile.scala:18) ~[classes/:na]
at controllers.Application$$anonfun$verify$1.apply(Application.scala:28) ~[classes/:2.1-SNAPSHOT]
at controllers.Application$$anonfun$verify$1.apply(Application.scala:17) ~[classes/:2.1-SNAPSHOT]
at play.api.mvc.Action$$anon$1.apply(Action.scala:170) ~[play_2.9.1.jar:2.1-SNAPSHOT]
at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126) ~[play_2.9.1.jar:2.1-SNAPSHOT]
at play.core.ActionInvoker$$anonfun$receive$1$$anonfun$6.apply(Invoker.scala:126) ~[play_2.9.1.jar:2.1-SNAPSHOT]
I see that your using the old plugin. Re read the info and update your code accordingly.
I've also encountered this problem, I'm not shure why it's happening. But I'm on it.
I have updated, but unfortunately, the problem persists.
Can you maybe provide me some workaround? Am I using the plugin in a wrong manner?
This is fixed in 1.0.2.
The API has changed a bit, so check the README or the https://github.com/leon/play-salat/tree/master/sample to see how to get it started.
I'm seeing this on my current project: "se.radley" %% "play-plugins-salat" % "1.0.9"
Restart play fixes it.