Details
-
Bug
-
Resolution: Done
-
Major - P3
-
None
-
None
-
None
-
None
Description
This is borderline bug / feature request.
I have been happily using the DBCollection.setObjectClass(CUSTOM_CLASS) feature in my app, but unfortunately, any time I have a DBRef from one DBObject to another, I cannot direct DBRef.fetch() (actually it is DBRefBase.fetch()) to use a custom DBObject class. It always uses BasicDBObject.
One solution would be to have an optional property of DBRef to configure an object class. If none is specified the default behavior is to use BasicDBObject.
Current impl code snippet (from github):
public DBObject fetch() {
if (_loadedPointedTo)
return _pointedTo;
if (_db == null)
throw new RuntimeException("no db");
if (D)
{ System.out.println("following db pointer. ref to ns:" + _ns); Throwable t = new Throwable(); t.fillInStackTrace(); t.printStackTrace(); }final DBCollection coll = _db.getCollectionFromString(_ns);
_pointedTo = coll.findOne(_id);
_loadedPointedTo = true;
return _pointedTo;
}