I have a case class that looks like this:
import com.novus.salat.annotations.raw.Key
import org.bson.types.ObjectId
case class Users(
_id: ObjectId,
email: String,
password: String,
firstName: String,
lastName: String,
company: Option[String],
position: Option[String],
enabled: Boolean)
And a simple SalatDAO:
import com.novus.salat.dao.SalatDAO
import org.bson.types.ObjectId
import com.novus.salat.global._
object UsersDAO extends SalatDAO[Users, ObjectId](
collection = MongoFactory.getCollection("usersCollection"))
So now I want to change "_id" to "id". I thought that Salat @Key annotation is indeed for that purpose. So I write:
...
@Key("_id") id: ObjectId,
...
And when I try UsersDAO.find(MongoDBObject.empty)
I get an exception
java.lang.NoSuchMethodException: com...Users$.apply$default$1()
What interesting - if I do the same thing but for another class where "id: String" I get this exception
java.lang.Exception: class com...AnotherClass requires value for 'id'
Can anyone throw sunshine on that please?
you need to fix your import. Use
import com.novus.salat.annotations._
to properly target the @Key
annotation to the getter
.