java - a field name "ClassName" is being inserted into mongodb by morphia -


i'm pretty new mongodb , morphia, after starting using it, realize there part in mongodb document, record contains filed name "classname" value of class morphia mapped.

{ "_id" : objectid("51e7a85e300441e5885316c0"), "classname" : "models.user", "imgurl" : "", "uname" : "alex"} 

is normal? feel violating integrity of data in db, there anyway around it?

you can explicitly disable classname attribute: @entity(noclassnamestored = true)

i'm suppressing attribute, if there single entity class. if i'm subclassing entity, i'm explicitly enabling (which default, sure).

if i'm not mistaken, morphia clever enough guess correct subclass based on properties if there no classname (based on reflection). if have attribute mongoknowledge in subclass developer of person , subclass manager doesn't have it, morphia know documents mongoknowledge must of class developer. strictly speaking classname required if subclasses have same attributes; however, wouldn't rely on much.

i haven't tried rename entity classes, cause issues. there's long standing issue provide @polimorphic annotation , fix that. see https://code.google.com/p/morphia/issues/detail?id=22


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -