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!