How could I retrieve all the relationships from a (spring-data-)neo4j database?

1.4k Views Asked by At

Is there a way to simply retrieve all relationships of a certain type - where type is a @RelationshipEntity annotated class - from a spring-data-neo4j [SDN] database? (working with 2.0.0.RC1 & embedded DB)

When I try the method provided by SDN :

relationShipRepository.findAll()

it gives me the following error:

org.neo4j.graphdb.NotFoundException: __type__ property not found for RelationshipImpl #9672 of type 7 between Node[4844] and Node[4875].

Full stacktrace: http://pastebin.com/j2gqcjxh (though looking

A solution would be to use the low level (neo4j) API (namely GraphDatabaseService ) to retreive all nodes, and then for each node retreive all their relationships and verify if their __type__ field matches the type of relationship I'm interested in. But then why provide findAll method for relationships?

Simple explanation is that the the advised interface is the same for nodes and relationships - but does any documentation say that we are not allowed to use findAll for relationships?

Or: examining the relationship entity in the db, it contradicts the exception, because type is defined correctly as expected and it is possible to retreive the relationship through highlevel (SDN) API once you retrieved the node and you call getRelationship*(..)

On other note: does anyone know if ImpermanentDataGraph service will be included in v 2+?

1

There are 1 best solutions below

3
On BEST ANSWER

Are you looking for the relationships that are created as Relationship-entities in SDN or all relationships?

What is your use-case?

Relationship-Entites are also added to the index. Is the relationship 9672 a relationship-entity?

For the Relationship-Repository - that depends on the TypeRepresentationStrategy, if the "indexed-strategy" is used, Relationship-Enties are also available in their respective repository (but not globally).

In Neo4j 1.6.M01 there is a new [GlobalGraphOperations][1] class that also has getAllRelationships().

ImpermanentGraphDatabase is out of the Neo4j-testing toolchain. And it will stay there (and improve in performance) in v2+.