Grails Domain.get() returns null for mongo's ObjectId
        Posted  
        
            by 
                Shashank Agrawal
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Shashank Agrawal
        
        
        
        Published on 2014-08-22T04:16:10Z
        Indexed on 
            2014/08/22
            4:20 UTC
        
        
        Read the original article
        Hit count: 301
        
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?
© Stack Overflow or respective owner