I have a simple relationship test that I am trying to run to create a unique node using Rest API (java-rest-binding) https://github.com/neo4j/java-rest-binding but unfortunately I am stuck on something, here are the details: (the non-unique node and relationship works perfectly fine, its with this that it doesn't, most likely I am doing something naive (pardon my 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 i use this on the 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 basically Fails with:
java.lang.RuntimeException: Error retrieving or creating node for key name and value AnirudhVyas with index users
at org.neo4j.rest.graphdb.ExecutingRestAPI.getOrCreateNode(ExecutingRestAPI.java:448)
at org.neo4j.rest.graphdb.RestAPIFacade.getOrCreateNode(RestAPIFacade.java:223)
at xxxx.xxxx.xxxx.graph.UserModelCreateTasteKeyNeo4JBatchCallback.recordBatch(UserModelCreateTasteKeyNeo4JBatchCallback.java:61)
Copyright License:
Author:「anirudh.vyas」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/16680802/getorcreate-for-java-rest-api-neo4j-fails