mongoTemplate update document with underline("_") fields throws NullPointerException -
the model class:
class test { private string id; private set<string> tags; private set<string> tags_value; public string getid() { return id; } public void setid(string id) { this.id = id; } public set<string> gettags() { return tags; } public void settags(set<string> tags) { this.tags = tags; } public set<string> gettags_value() { return tags_value; } public void settags_value(set<string> tags_value) { this.tags_value = tags_value; }
}
the update method:
public static void updatetest(mongotemplate mongotemplate, test test){ string id = test.getid(); update update = new update(); if(null!=test.gettags()) update.set("tags", test.gettags()); if(null!=test.gettags_value()) update.set("tags_value", test.gettags_value()); mongotemplate.findandmodify(new query(criteria.where("id").is(id)), update, test.class, "test"); }
then trying update document in collections this: (i'm sure connection , authentication well)
set<string> tags = new hashset<>(); set<string> tags_value = new hashset<>(); tags.add("tag11"); tags.add("tag12"); tags.add("tag13"); tags_value.add("tag1"); tags_value.add("tag2"); tags_value.add("tag3"); test t = new test(); t.setid("5992adf2c65d171fccc6afe0"); t.settags(tags); t.settags_value(tags_value); updatetest(mongotemplate, t);
then got nullpointerexception follows:
exception in thread "main" java.lang.nullpointerexception @ org.springframework.data.mapping.context.abstractmappingcontext.getpersistentpropertypath(abstractmappingcontext.java:254) @ org.springframework.data.mapping.context.abstractmappingcontext.getpersistentpropertypath(abstractmappingcontext.java:235) @ org.springframework.data.mapping.context.abstractmappingcontext.getpersistentpropertypath(abstractmappingcontext.java:210) @ org.springframework.data.mongodb.core.convert.querymapper$metadatabackedfield.getpath(querymapper.java:867) @ org.springframework.data.mongodb.core.convert.querymapper$metadatabackedfield.<init>(querymapper.java:758) @ org.springframework.data.mongodb.core.convert.querymapper$metadatabackedfield.<init>(querymapper.java:735) @ org.springframework.data.mongodb.core.convert.updatemapper$metadatabackedupdatefield.<init>(updatemapper.java:219) @ org.springframework.data.mongodb.core.convert.updatemapper.createpropertyfield(updatemapper.java:190) @ org.springframework.data.mongodb.core.convert.querymapper.getmappedobject(querymapper.java:129) @ org.springframework.data.mongodb.core.convert.querymapper.convertsimpleordbobject(querymapper.java:378) @ org.springframework.data.mongodb.core.convert.querymapper.getmappedkeyword(querymapper.java:261) @ org.springframework.data.mongodb.core.convert.querymapper.getmappedobject(querymapper.java:105) @ org.springframework.data.mongodb.core.mongotemplate.dofindandmodify(mongotemplate.java:1845) @ org.springframework.data.mongodb.core.mongotemplate.findandmodify(mongotemplate.java:735) @ org.springframework.data.mongodb.core.mongotemplate.findandmodify(mongotemplate.java:726) @ com.qiyi.util.admintool.updatetest(admintool.java:72) @ com.qiyi.util.admintool.main(admintool.java:94)
but when change "tags_value" "tagsvalue", turns well. remove underline character , change specific getters , setter methods , update.set("tagsvalue", test.gettagsvalue()). bug?
Comments
Post a Comment