Grails Domain.get() returns null for mongo's ObjectId
- by Shashank Agrawal
I'm using grails 2.3.5 with mongodb 3.0.1 and no hibernate installed. I've a domain class which uses mongo's ObjectId.
import org.bson.types.ObjectId
class Category {
ObjectId id
String name
}
And has a record in mongo database:
{
"_id": ObjectId("53f6c34c33a429240e2ab471"),
"name": "art",
"version": NumberLong("41")
}
When I do, Category.get(new ObjectId("53f6c34c33a429240e2ab471")) somewhere in grails app, it returns null but when I do Category.get("53f6c34c33a429240e2ab471") it then actually returns the result.
Why, get() method does not process ObjectId type?