getOrCreate for java-rest-api neo4j fails -
i have simple relationship test trying run create unique node using rest api (java-rest-binding) https://github.com/neo4j/java-rest-binding unfortunately stuck on something, here details: (the non-unique node , relationship works fine, doesn't, doing naive (pardon lack on knowledge of neo4j).
final usermodel usermodel = new usermodel(); final hashmap<string, object> umodelattributes = new hashmap<string, object>(0); umodelattributes.put("name", "anirudhvyas"); usermodel.setattributes(umodelattributes); final hashset<action> buyhistory = new hashset<action>(); final action buyaction = new action(); final productmodel productmodel = new productmodel(); final hashmap<string, object> attributes = new hashmap<string, object>(0); attributes.put("name", "mercedes benz "); attributes.put("make", "mercedes benz"); attributes.put("model", "sls 550"); attributes.put("year", "2014"); productmodel.setattributes(attributes); buyaction.setproduct(productmodel); buyhistory.add(buyaction); usermodel.setbuyhistory(buyhistory); system.out.println("before"); new usermodeldao().createcompletetree(usermodel); system.out.println("completed >>> if use on dao:
final restnode root = api.getorcreatenode(api.index().fornodes("users", maputil.stringmap(indexmanager.provider, "lucene", "type", "fulltext")), "name", m .getattributes().get("name"), m.getattributes()); api.getorcreatenode(api.index().fornodes("products", maputil.stringmap(indexmanager.provider, "lucene", "type", "fulltext")), "name", buyaction.getproduct().getattributes().get("name"), buyaction.getproduct().getattributes()), relationshiptypes.bought); this fails with:
java.lang.runtimeexception: error retrieving or creating node key name , value anirudhvyas index users @ org.neo4j.rest.graphdb.executingrestapi.getorcreatenode(executingrestapi.java:448) @ org.neo4j.rest.graphdb.restapifacade.getorcreatenode(restapifacade.java:223) @ xxxx.xxxx.xxxx.graph.usermodelcreatetastekeyneo4jbatchcallback.recordbatch(usermodelcreatetastekeyneo4jbatchcallback.java:61)
there several ways it, 1 of them using cypher:
match a.name! = 'nametofound' create unique a-[:relationship]-c:label return c use inside queryengine. works charm, please @ following link more details: http://docs.neo4j.org/chunked/milestone/query-create-unique.html
java code here:
protected static restnode createorgetexistingnode(string key, string valuefor, string rel, string label){ restnode node = null; final queryresult<map<string, object>> result = graphrestservice.queryengine.query(string.format("match node node.%s! ='%s' " + "create unique node-[:%s]-c:%s return c" , key, valuefor, rel, label), maputil.map("reference", 0)); (map<string, object> column : result) { node = (restnode) column.get("c"); } return node; }
Comments
Post a Comment