cypher - Issues while retrieving existing nodes using Spring Data Neo4j -
i created simple sdn project retrieve existing nodes database. in repository, defined custom query using @query annotation
@query("match (emp:employee) emp.empname={0} return emp")
public employee findbyname(string empname);
@relationshipentity(type = "has_address") class addressrelationship { @graphid long id; @startnode employee employee = null; @endnode address address = null; public addressrelationship(employee employee, address address) { this.employee = employee; this.address = address; } } @nodeentity @typealias("employee") public class employee { @graphid long id; string empname = null; @relatedto(type = "has_address", direction = direction.outgoing) @fetch set<address> addresses; public void addressemplployee(address address) { if (addresses == null) { addresses = new hashset<address>(); } //addressrelationship addressrelationship = new addressrelationship(this, address); addresses.add(address); } public set<address> getaddresses() { return addresses; } public void setaddresses(set<address> addresses) { this.addresses = addresses; } public long getid() { return id; } public void setid(long id) { this.id = id; } public string getempname() { return empname; } public void setempname(string empname) { this.empname = empname; } }
with query, on execution below error message:
no primary sdn label exists .. (i.e 1 starting _)
i googled issue , tried use below query:
match (emp:employee:_employee) emp.employeeid={0} return emp
this query runs doesn't return response.
one important thing here haven't created existing nodes using sdn(i googled , found sdn adds metadata e.g, _ nodes/relationships).
however, if created (employee)-[has_address]->(address) pattern data using sdn, below query works fine:
match (emp:employee) emp.empname={0} return emp
in case, found 1 other issue returned address data while i'm returning employee in query. i'm able obtain addresses employee entity object.
any pointers on above issues?
ps - neo4j running in standalone server mode.
regards, rahul
i resolve above issues in following steps:
- no primary sdn label exists .. (i.e 1 starting _) - in sdn 3.3.0, existing nodes, sdn requires label (in case, _employee), data migration required. in sdn 4.0, seems no longer needed haven't tried 4.0 yet.
- returning address data while i'm returning employee in query - removing @fetch on set addresses in employee resolved this, however, addresses nodeids still returned.
to run sdn 3.x.x existing data, following data migration required:
- add additional nodelabel(preceding original label _) nodes, e.g, add _employee label employee nodes.
- add __type__ property nodes , relationships value qualified name appropriate domain/model classes, e.g, match (n:employee) set n.__type__="org.neo4j.domain.employee"
cheers,
rahul
Comments
Post a Comment