1

I used in Spring Data Neo4j 3.1.2 this query to create a person and get the id of it:

Create (n:Person {gender:'MALE',sic:'sic-123'}) return id(n)

with my Neo4JTemplate i execute this query with:

neo4JTemplate.query("Create (n:Person {gender:{gender},sic:{sic}}) "+ 
"return id(n)",ImmutableMap.of("gender","MALE","sic","sic-123");

Now i want to use Spring Data Neo4J 4.0.0.M1, because of it's server-support.

In SDN 4 queries can executed with the Neo4jTemplate by

void neo4jTemplate.execute(String jsonStatement) 
//CREATE, MERGE or DELETE the node

or

<T> T queryForObject(Class<T> objectType, String cypher, Map<String,?> parameters) 
//The RETURN of an Object possible but read only - mode (no creation)

<T> Iterable<T> queryForObjects(Class<T> objectType, String cypher,
Map<String,?> parameters) 

//The RETURN of Objects possible but read only - mode (no creation)


Iterable<Map<String,Object>> query(String cypher,
Map<String,?> parameters)   
//The RETURN of Objects possible but read only - mode (no creation)

My Question now is: how can i use the neo4jTemplate to use only ONE query that create my node and get me the id of it?

P.S.: The creation and return of the id works, but i want only one query to manage this problem.

4

1 回答 1

1

目前您无法使用 Neo4jTemplate 执行此类查询。只允许非修改 Cypher 查询返回结果。

您必须保存 Person 实体,然后使用保存后填充的 id。

这计划被修复(虽然不能保证修复版本) - 请参阅https://github.com/neo4j/neo4j-ogm/issues/22

于 2015-07-15T12:24:51.730 回答