英文:
How can we create an node with manual query in spring data neo4j?
问题
以下是要翻译的代码部分:
创建一个节点,通过repo接口手动创建,但是neo4j驱动程序内部会引发异常
Caused by: org.neo4j.driver.exceptions.ClientException: 无效输入 '{':预期参数 (第1行,第22列 (偏移量:21))
"CREATE(a:Association {a.name:{0}}) RETURN true"
^
以下是代码片段:
@Repository
public interface AssociationRepo extends Neo4jRepository {
@Query("CREATE(a:Association {a.name:{0}}) RETURN a") -- 这一行有什么问题?
Association addAssociation(String name);
}
调用者代码:
@Override
public boolean addAssociationToCountry(String countryCode, Association association) {
repo.addAssociation(association.getName());
return true;
}
英文:
Create an node manually via repo interface but neo4j driver internally raise an exception as
<pre><code>
Caused by: org.neo4j.driver.exceptions.ClientException: Invalid input '{': expected a parameter (line 1, column 22 (offset: 21))
"CREATE(a:Association {a.name:{0}}) RETURN true"
^
</pre></code>
Below is the code snippet:
<pre><code>
`@Repository
public interface AssociationRepo extends Neo4jRepository {
@Query("CREATE(a:Association {a.name:{0}}) RETURN a") -- what is wrong in this line ?
Association addAssociation(String name);
}`
</pre></code>
Caller code :
<pre><code>
` @Override
public boolean addAssociationToCountry(String countryCode, Association association) {
repo.addAssociation(association.getName());
return true;
}`
</pre></code>
I checked whole of internet but didn't find any solution.`
答案1
得分: 1
你的语法几乎正确。问题在于花括号内部使用的节点名称。
应该是(a:Association {name:{0}})
,而不是(a:Association {a.name:{0}})
,因为节点边界已经定义了属性属于这个节点。
英文:
You are very close to the right syntax. The problem is the node name, you are using within the curly brackets.
Instead of (a:Association {a.name:{0}})
it should be (a:Association {name:{0}})
because the node boundaries already define that the properties belong to this very node.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论