0

I keep getting this error with my Play 2.0 application:

play.core.ActionInvoker$$anonfun$receive$1$$anon$1: Execution exception [[MatchError: 4f7f4ae4251735803a942b2c (of class org.bson.types.ObjectId)]]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:82) [play_2.9.1.jar:2.0]
    at play.core.ActionInvoker$$anonfun$receive$1.apply(Invoker.scala:63) [play_2.9.1.jar:2.0]
    at akka.actor.Actor$class.apply(Actor.scala:290) [akka-actor.jar:2.0]
    at play.core.ActionInvoker.apply(Invoker.scala:61) [play_2.9.1.jar:2.0]
    at akka.actor.ActorCell.invoke(ActorCell.scala:617) [akka-actor.jar:2.0]
    at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:179) [akka-actor.jar:2.0]
Caused by: scala.MatchError: 4f7f4ae4251735803a942b2c (of class org.bson.types.ObjectId)
    at com.novus.salat.transformers.in.LongToInt$class.transform(Injectors.scala:216) ~[salat-core_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]
    at com.novus.salat.transformers.in.package$$anon$31.transform(Injectors.scala:180) ~[salat-core_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]
    at com.novus.salat.transformers.Transformer$$anonfun$transform_$bang$1.apply(Transformer.scala:71) ~[salat-core_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]
    at com.novus.salat.transformers.Transformer$$anonfun$transform_$bang$1.apply(Transformer.scala:71) ~[salat-core_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]
    at scala.Option.flatMap(Option.scala:146) ~[scala-library.jar:0.11.2]
    at com.novus.salat.transformers.Transformer.transform_$bang(Transformer.scala:71) ~[salat-core_2.9.1-0.0.8-SNAPSHOT.jar:0.0.8-SNAPSHOT]

My model is very simple and I use SalatDao-flavored DB access:

case class Gossip(@Key("_id") id: org.bson.types.ObjectId, title: String, link: String, description: String, permalink: String,
                  image: String, date: String) {}
object GossipDAO extends SalatDAO[Gossip, ObjectId](
  collection = MongoConnection()("gossips")("items"))

The error is thrown when I call this:

val gossips = GossipDAO.find(ref = MongoDBObject("modificationDate" -> MongoDBObject("$gte" -> startDate))).toList

I've loaded data to my MongoDB via some other script, and they seem to be OK, since I'm able to find them in MongoDB shell with:

 db.items.find({_id:ObjectId("4f7f4ae4251735803a942b2c")})

What's more if I change the startDate condition so as no objects match it, my code runs fine. This indicates that the query is correct but the transformation from MongoDBObject to Scala's Gossip class fails.

Is there something wrong with the above code?

UPDATE

  • My dependencies are only this:

    val appDependencies = Seq( "com.mongodb.casbah" %% "casbah" % "2.1.5-1", "com.novus" %% "salat-core" % "0.0.8-SNAPSHOT" )

  • I use 'modificationDate', because it is a field in the mongoDB collection object.

  • When I execute db.items.find({_id:ObjectId("4f7f4ae4251735803a942b2c")}) I get this:

https://gist.github.com/2928862

  • if you simply fetch the whole collection, are same kind of problem happening?

I don't know how to fetch all objects with salat DAO. But when I had my case class without 'id' key, I was able to do just db.find() on MongoConnection and it would return all the available objects and convert them into Model objects. The same solution, when I've added 'id' key produced the same error as above.

Marcin Cylke
  • 2,100
  • 2
  • 21
  • 40
  • What happens if you do: db.items.find({ case ObjectId("4f7f4ae4251735803a942b2c") => true }) – Viktor Klang Jun 11 '12 at 22:09
  • I get this: Tue Jun 12 08:04:46 SyntaxError: missing : after property id (shell):1 -- keep in mind I'm executing that "db.items.find()" from Mongo Shell, not scala. Should it work there? My Mongo version is 2.0.3 – Marcin Cylke Jun 12 '12 at 06:05
  • 1
    Some wonders. Are you using the play 2 salat module (https://github.com/leon/play-salat) or did you imported all needed stuffs (http://ska-la.blogspot.be/2012/03/play-20-and-salat-mongodb-dao-provider.html)? The second wonder is you filter on "modificationDate" but there is only a 'date' in you model. And the last question, if you simply fetch the whole collection, are same kind of problem happening ? – Andy Petrella Jun 14 '12 at 07:22
  • I've updated my question with answers. – Marcin Cylke Jun 14 '12 at 07:46

1 Answers1

0

Well, it seems that deleting 'target' directory and running Play20 again solved the issue. Must have been some old classes info in there.

Marcin Cylke
  • 2,100
  • 2
  • 21
  • 40