Java – the font name “classname” is inserted into mongodb by morphia

I just started using mongodb and morphia. I realized that there was an extra part in the mongodb file. The record contained a name named "classname", which was the same as the value of the class mapped by morphia

{ "_id" : ObjectId("51e7a85e300441e5885316c0"),"className" : "models.User","imgurl" : "","uname" : "alex"}

Is this normal? I think this violates the integrity of the data in the database. Is there any way to bypass it?

Solution

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

I usually suppress attributes if there is an entity class If I am a child entity, I explicitly enable it (this is the default, but just to be sure)

If I'm not wrong, morphia is smart enough to guess the correct subclass based on attributes, even without classname (reflection based) Therefore, if your subclass "developer" has a property mongoknowledge and your subclass manager has no property, morphia will know that the document with mongoknowledge must be a developer class So strictly speaking, classname is only required if your subclass has the same properties; But I won't rely too much on it

I didn't try to rename the entity class, but it may cause problems Providing a @ polimorphic annotation has a long-standing problem and is fixed with it see https://code.google.com/p/morphia/issues/detail?id=22

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>