您好我正在尝试插入一个节点的两个属性....我正在尝试如下..
我正在尝试向CUSTOMER NODE添加两个属性
1.name和2.TOTAL_CALL_DURATION
如何添加两个属性
try ( Transaction tx = graphDb.beginTx() )
{
String queryString = "MERGE (n:CUSTOMER {name:{name},TOTAL_CALL_DURATION:{TOTAL_CALL_DURATION}}) RETURN n";
Map<String, Object> callerProperties = new HashMap<>();
callerProperties.put( "name", callerName );
callerProperties.put("TOTAL_CALL_DURATION", 120);
resultIterator_caller = execEngine.execute( queryString, callerProperties ).columnAs( "n" );
tx.success();
}
我得到的错误如下:
Exception in thread "main" org.neo4j.cypher.ParameterNotFoundException: Expected a parameter named TOTAL_CALL_DURATION
at org.neo4j.cypher.internal.compiler.v2_1.pipes.QueryState$$anonfun$getParam$1.apply(QueryState.scala:45)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.QueryState$$anonfun$getParam$1.apply(QueryState.scala:45)
at scala.collection.MapLike$class.getOrElse(MapLike.scala:128)
at scala.collection.AbstractMap.getOrElse(Map.scala:58)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.QueryState.getParam(QueryState.scala:45)
at org.neo4j.cypher.internal.compiler.v2_1.commands.expressions.ParameterExpression.apply(ParameterExpression.scala:27)
at org.neo4j.cypher.internal.compiler.v2_1.helpers.PropertySupport$$anonfun$firstNullPropertyIfAny$1.isDefinedAt(PropertySupport.scala:29)
at org.neo4j.cypher.internal.compiler.v2_1.helpers.PropertySupport$$anonfun$firstNullPropertyIfAny$1.isDefinedAt(PropertySupport.scala:28)
at scala.collection.TraversableOnce$$anonfun$collectFirst$1.apply(TraversableOnce.scala:132)
at scala.collection.TraversableOnce$$anonfun$collectFirst$1.apply(TraversableOnce.scala:131)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
at scala.collection.TraversableOnce$class.collectFirst(TraversableOnce.scala:131)
at scala.collection.AbstractTraversable.collectFirst(Traversable.scala:105)
at org.neo4j.cypher.internal.compiler.v2_1.helpers.PropertySupport$.firstNullPropertyIfAny(PropertySupport.scala:28)
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergeNodeAction.ensureNoNullNodeProperties(MergeNodeAction.scala:95)
at org.neo4j.cypher.internal.compiler.v2_1.mutation.MergeNodeAction.exec(MergeNodeAction.scala:73)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPipe.org$neo4j$cypher$internal$compiler$v2_1$pipes$ExecuteUpdateCommandsPipe$$exec(ExecuteUpdateCommandsPipe.scala:57)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPi$$$$1019fdff8b266d7d9d5647386930b3d8$$$$ands$1$$anonfun$apply$2.apply(ExecuteUpdateCommandsPipe.scala:46)
at org.neo4j.cypher.internal.compiler.v2_1.pipes.ExecuteUpdateCommandsPi$$$$1019fdff8b266d7d9d5647386930b3d8$$$$ands$1$$anonfun$apply$2.apply(ExecuteUpdateCommandsPipe.scala:46)
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)
at scala.collection.Iterator$$anon$13.hasNext(Iterator.scala:371)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply$mcZ$sp(ClosingIterator.scala:37)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:34)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$hasNext$1.apply(ClosingIterator.scala:34)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator$$anonfun$failIfThrows$1.apply(ClosingIterator.scala:93)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.decoratedCypherException(ClosingIterator.scala:102)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.failIfThrows(ClosingIterator.scala:91)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.hasNext(ClosingIterator.scala:34)
at scala.collection.Iterator$class.foreach(Iterator.scala:727)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.foreach(ClosingIterator.scala:28)
at scala.collection.generic.Growable$class.$plus$plus$eq(Growable.scala:48)
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:176)
at scala.collection.mutable.ListBuffer.$plus$plus$eq(ListBuffer.scala:45)
at scala.collection.TraversableOnce$class.to(TraversableOnce.scala:273)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.to(ClosingIterator.scala:28)
at scala.collection.TraversableOnce$class.toList(TraversableOnce.scala:257)
at org.neo4j.cypher.internal.compiler.v2_1.ClosingIterator.toList(ClosingIterator.scala:28)
at org.neo4j.cypher.internal.compiler.v2_1.EagerPipeExecutionResult.<init>(EagerPipeExecutionResult.scala:32)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1$$anonfun$apply$2.apply(ExecutionPlanBuilder.scala:125)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1$$anonfun$apply$2.apply(ExecutionPlanBuilder.scala:119)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionWorkflowBuilder.runWithQueryState(ExecutionPlanBuilder.scala:168)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1.apply(ExecutionPlanBuilder.scala:118)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anonfun$getExecutionPlanFunction$1.apply(ExecutionPlanBuilder.scala:103)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anon$1.execute(ExecutionPlanBuilder.scala:68)
at org.neo4j.cypher.internal.compiler.v2_1.executionplan.ExecutionPlanBuilder$$anon$1.execute(ExecutionPlanBuilder.scala:67)
at org.neo4j.cypher.internal.ExecutionPlanWrapperForV2_1.execute(CypherCompiler.scala:159)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:76)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:71)
at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:84)
at com.emc.neo4jConnectivity.NodeCreation.createNodes(NodeCreation.java:84)
at com.emc.neo4jConnectivity.NodeCreation.main(NodeCreation.java:136)
答案 0 :(得分:2)
您的代码没有任何问题,我已将其转换为运行良好的自包含groovy
脚本,没有任何错误。
尝试提供一个最小的可行测试用例,显示您正在观察的错误
供参考,这是脚本:
@Grapes([
@Grab(group="org.neo4j", module="neo4j-kernel", version="2.1.8", classifier="tests"),
@Grab(group="org.neo4j", module="neo4j-kernel", version="2.1.8"),
@Grab(group="org.neo4j", module="neo4j-cypher", version="2.1.8")
])
import org.neo4j.test.TestGraphDatabaseFactory
import org.neo4j.cypher.javacompat.ExecutionEngine
import org.neo4j.helpers.collection.IteratorUtil
def graphDb = new TestGraphDatabaseFactory().newImpermanentDatabaseBuilder().newGraphDatabase()
def executionEngine = new ExecutionEngine(graphDb)
def resultIterator_caller
def tx = graphDb.beginTx()
try {
String queryString = "MERGE (n:CUSTOMER {name:{name},TOTAL_CALL_DURATION:{TOTAL_CALL_DURATION}}) RETURN n";
Map<String, Object> callerProperties = new HashMap<>();
callerProperties.put( "name", "abc" );
callerProperties.put("TOTAL_CALL_DURATION", 120);
resultIterator_caller = executionEngine.execute( queryString, callerProperties ).columnAs( "n" );
tx.success()
} finally {
tx.close()
}
// we need another tx to consume the result (since we're returning node instances)
transaction = graphDb.beginTx()
try {
assert resultIterator_caller.hasNext()
def nextNode = resultIterator_caller.next()
assert nextNode.getProperty("name",null) == "abc"
assert nextNode.getProperty("TOTAL_CALL_DURATION",null) == 120
assert !resultIterator_caller.hasNext()
tx.success()
} finally {
tx.close()
}