Using Salatdao without Case Classes

108 views
Skip to first unread message

Anurag Laddha

unread,
May 12, 2014, 2:05:01 PM5/12/14
to scala...@googlegroups.com
Greetings,

I'm using SalatDAO for reading/writing data from Mongodb (using Casbah)
I'm able to get things to work with case class but not with a regular scala class

// Model
class CollectionFoo(@Key("_id") var fooId: String,
                       @Key("foo") var fooHere : String,
                       @Key("bar") var barHere : Int,
                       @Key("ps") var processStatus : String = "") {
}


//Simple DAO using Salat
object AnuragTestDAO extends SalatDAO[CollectionFoo, String](collection = db.anuragTestCollection) with GenericDAO with DataStoreExceptionWrapper {
  def findItemById(fooId: String) = {
    exceptionWrapper {
      val results = find(ref = MongoDBObject("_id" -> fooId)).toList
      results match {
        case Nil => None
        case x :: xs => Some(x)
      }
    }
  }
}


//Test case using Spec2
@RunWith(classOf[JUnitSuiteRunner])
class AnuragDAOTest  extends Specification with Logging with JUnit {

  "AnuragModel" should {
    "get elements by id" in new AnuragModelContextNoChange {
      AnuragTestDAO.findItemById("1").size must_== 1
    }
}

I get following error:

org.specs.runner.SpecError: com.novus.salat.util.GraterGlitch: 

      GRATER GLITCH - unable to find or instantiate a grater using supplied path name

      REASON: Class com.flipkart.sindbad.data.model.CollectionFoo is not an instance of CaseClass

      Context: 'CustomSalatContext'
      Path from pickled Scala sig: 'com.flipkart.sindbad.data.model.CollectionFoo'



The same thing works perfectly fine if i make class CollectionFoo a case class. 

How can i make SalatDAO work for non case classes?

Thanks!

rose katherine toomey

unread,
May 12, 2014, 2:08:55 PM5/12/14
to scala-salat
Hi Anurag,

Salat supports case classes and abstract classes/traits whose concrete implementation is a case class.

Please look at the section titled "What doesn't Salat support?" in the README -


Thanks,
Rose


--
You received this message because you are subscribed to the Google Groups "scala-salat" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-salat...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages