Tuesday 15 January 2013

java - Why Neo4jTemplate covers nodes number but not its content? -



java - Why Neo4jTemplate covers nodes number but not its content? -

this 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>

and 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 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>

and want autowire neo4jtemplate form neo4j standalone server:

@repository public class employeedao_neo4j implements employeedao { @inject private neo4jtemplate neo4jtemplate; @override public list<map<string, object>> findall(string query) { //object node address result<map<string, object>> result = neo4jtemplate.query("match (emp:`empbase`) homecoming 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)); homecoming list; } }

the returned list 4 element 1 says in every system.out.println above code that: {e_id=1, e_bossid=null, e_name='null'} not populated, because test info are:

$ cat /tmp/empbase.csv e_id,e_bossid,e_name 11,11,smith 12,11,johnson 13,11,roberts 14,13,doe

the line results gives:{emp=http://localhost:7474/db/data/node/1}

the info in neo4j server comes csv import. empfull.csv:

create empbase; // import info , schema empbase; '_empbase' required springdata-neo4j using periodic commit 500 load csv headers "file:/tmp/empbase.csv" 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 headers "file:/tmp/empbase.csv" 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);

is bug of sdn or sth wrong config?

ps. db/neo4j/data/graph.db xml config never generated. run project 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() { homecoming e_id; } public integer gete_bossid() { homecoming e_bossid; } public string gete_name() { homecoming e_name; } @override public string tostring() { homecoming "{" + "e_id=" + e_id + ", e_bossid=" + e_bossid + ", e_name='" + e_name + '\'' + '}'; }

}

because used wrong property names in import, prefixed them neo_eb instead of e_. had typos e.g. in e_bossid

create empbase; // import info , schema empbase; '_empbase' required springdata-neo4j using periodic commit 500 load csv headers "file:/tmp/empbase.csv" 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 headers "file:/tmp/empbase.csv" 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 csv neo4j spring-data-neo4j

No comments:

Post a Comment