gpt4 book ai didi

java - 为什么 Neo4jTemplate 涵盖节点数而不涵盖其内容?

转载 作者:行者123 更新时间:2023-12-01 12:19:07 25 4
gpt4 key购买 nike

这是我的 pom.xml:

<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j-rest</artifactId>
<version>3.2.1.RELEASE</version>
</dependency>

和config.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:neo4j="http://www.springframework.org/schema/data/neo4j"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=" http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/neo4j
http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd">

<!-- REST Connection to Neo4j server -->
<bean id="graphDatabaseService"
class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
<constructor-arg index="0" value="http://localhost:7474/db/data" />

</bean>

<!-- graphDatabaseService- Neo4j configuration (creates Neo4jTemplate) -->
<neo4j:config
storeDirectory="db/neo4j/data/graph.db"
base-package="x.y.z.mediator.domain.model"
graphDatabaseService="graphDatabaseService"/>

</beans>

我想从 neo4j 独立服务器中 Autowiring neo4jtemplate:

@Repository
public class EmployeeDAO_Neo4j implements EmployeeDAO {

@Inject
private Neo4jTemplate neo4jTemplate;


@Override
public List<Map<String, Object>> findAll(String query) {

//Object is the node address
Result<Map<String, Object>> result = neo4jTemplate.query("MATCH (emp:`EmpBase`) RETURN emp;", null);
//Below line results with: {emp=http://localhost:7474/db/data/node/1}
System.out.println("Results:"+ result.as(List.class).get(1).toString());


List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
Map<String, Object> map = null;



for(EmployeeBase u : result.to(EmployeeBase.class)) {
map = new HashMap<String, Object>( );
map.put(u.getE_id().toString(), u.toString());

list.add(map);
}

System.out.println(result.to(EmployeeBase.class).as(List.class).get(1));

return list;
}
}

返回的列表是 4 个元素一,但在上述代码的每个 System.out.println 中都表示:{e_id=1, e_bossId=null, e_name='null' } 所以它没有被填充,因为测试数据是:

$ cat /tmp/empbase.csv 
e_id,e_bossid,e_name
11,11,Smith
12,11,Johnson
13,11,Roberts
14,13,Doe

结果行仅给出:{emp=http://localhost:7474/db/data/node/1}

Neo4j服务器中的数据来自csv导入。 empfull.csv:

CREATE empbase;

// Import data and schema for empbase; the '_EmpBase' is required by SpringData-neo4j
USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:/tmp/empbase.csv" AS row
CREATE (:EmpBase:_EmpBase { neo_eb_id: row.e_id,
neo_eb_bossID: row.e_bossid,
neo_eb_name: row.e_name});

//Create index
CREATE INDEX ON :EmpBase:(neo_eb_id);

// Create relationships
LOAD CSV WITH HEADERS FROM "file:/tmp/empbase.csv" AS row
MATCH (employee:EmpBase:_EmpBase {neo_eb_id: row.e_id})
MATCH (manager:EmpBase:_EmpBase {neo_eb_id: row.e_bossid})
MERGE (employee)-[:REPORTS_TO]->(manager);

是SDN的bug还是这个配置有问题?

PS。xml 配置中的 db/neo4j/data/graph.db 永远不会生成。我使用 mvn clear package 运行这个项目PS2:这是 EmployeeBase.java

@NodeEntity
public class EmployeeBase {

@GraphId
private Long e_id;

private Integer e_bossId;
private String e_name;

public Long getE_id() {
return e_id;
}

public Integer getE_bossId() {
return e_bossId;
}

public String getE_name() {
return e_name;
}

@Override
public String toString() {
return "{" +
"e_id=" + e_id +
", e_bossId=" + e_bossId +
", e_name='" + e_name + '\'' +
'}';
}

}

最佳答案

由于您在导入中使用了错误的属性名称,因此您在所有属性名称前面加上了 neo_eb 而不是 e_ 前缀。您还存在一些拼写错误,例如在e_bossId

CREATE empbase;

// Import data and schema for empbase; the '_EmpBase' is required by SpringData-neo4j
USING PERIODIC COMMIT 500
LOAD CSV WITH HEADERS FROM "file:/tmp/empbase.csv" AS row
CREATE (:EmpBase:_EmpBase { e_id: row.e_id,
e_bossId: row.e_bossid,
e_name: row.e_name});

//Create index
CREATE INDEX ON :EmpBase:(e_id);

// Create relationships
LOAD CSV WITH HEADERS FROM "file:/tmp/empbase.csv" AS row
MATCH (employee:EmpBase:_EmpBase {e_id: row.e_id})
MATCH (manager:EmpBase:_EmpBase {e_id: row.e_bossid})
MERGE (employee)-[:REPORTS_TO]->(manager);

关于java - 为什么 Neo4jTemplate 涵盖节点数而不涵盖其内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26817096/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com