Hi,
I am experimenting with neo4j/cypher at the moment and I am puzzled about the following behaviour. I obtain references to two nodes if1 and cl1 using a node index. I do know that there is a relationship rel from if1 to cl1. I obtain this relationship and get its endNode. I expect this to be cl1, however, it is not! The endPoint is equal, but not identical to cl1!
This is a big problem if I navigate through graphs with cycles – I keep creating more and more objects all referencing the same nodes in the db!
What is the reasoning behind this feature? Is this perhaps just a bug? I had expected that neo4j behaves more like an ORM (hibernate etc) here: use a cache (usually implemented as a soft hash map) that maps ids to objects, and whenever a new object is requested from a datastore, first check whether it is already in memory and if so use the existing one.
Any advise / hint how to avoid this is appreciated!
Code below.
Full code here (can be checked out and executed as test case):
a drawing of the graph used in this example is here: http://goo.gl/VGxKR
Kind regards, Jens
@Test
public void testReferentialIntegrity() throws Exception {
Index<Node> nodeIndex = db.index().forNodes( "nodes" );
Node cl1 = nodeIndex.get("qname", "com.example.Class1").getSingle();
Node if1 = nodeIndex.get("qname", "com.example.Interface1").getSingle();
// single relationship
Relationship rel = if1.getRelationships(Direction.OUTGOING).iterator().next();
Node endNode = rel.getEndNode();
assertEquals(cl1,endNode); // succeeds
assertTrue(cl1==endNode); // fails !
}
--
--
--
--
--
Cheers, Jens
I had a look - this is a great idea but the problem for me is that this works for undirected graphs, whereas the algorithms I use work on directed graphs, i.e. I need the interface edu.uci.ics.jung.graph.DirectedGraph. I am new to blueprints, but it seems to support the idea of direction (with the Direction enum) - would you have any idea how to get a directed jung graph out of blueprints?
guery uses its own abstraction api at the moment (graph adapter, see http://code.google.com/p/gueryframework/source/browse/src/java/nz/ac/massey/cs/guery/GraphAdapter.java ) and it shouldn't be to hard to map this to blueprints / neo4j.
I have started to implement some performance tests to compare the different frameworks (http://code.google.com/p/graph-query-benchmarks/ ) and cypher on neo4j does not do very well there (it runs out of memory very quickly even for small graphs - tests used are here: http://graph-query-benchmarks.googlecode.com/svn/trunk/graph-query-benchmarks/src/nz/ac/massey/cs/graphbenchmarks/neo4j/ , the equivalent tests for guery are here: http://graph-query-benchmarks.googlecode.com/svn/trunk/graph-query-benchmarks/src/nz/ac/massey/cs/graphbenchmarks/guery/).
This is probably not a neo4j but a cypher issue, and I am keen to write an adapter to find out. guery is good at fast + low memory querying, but does not have any db functionality like transactions and persistency. But there might be some merit in combining it with neo4j to get the best of both worlds.
--
--
--