Play 2.0 and MongoDB interfacing with Salat

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.

Answers


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


Need Your Help

How do I add VisualStateManager to my Surface project?

wpf wpftoolkit pixelsense

I have a surface project and I would like to use controls designed in Blend. I added these controls to my microsoft surface project, but I receive an error when I try to compile it.

In amazon lambda, resizing multiple thumbnail sizes in parallel async throws Error: Stream yields empty buffer

node.js amazon-web-services imagemagick aws-lambda

I've adapted the Amazon example of resizing a photo in lambda to create multiple thumbnail sizes and run in parallel.