neo4j SDN cascaded delete...

76 views
Skip to first unread message

kiteflo

unread,
Feb 8, 2012, 2:00:36 AM2/8/12
to Neo4j
Good morning...

quick question regarding cascaded delete and SDN: we have two nodes
connected via realtionship and we are to delete node_A. SDN removes
the relationship correctly so finally we have node_B being lonely in
the graph.

Now there are several approaches we might follow, would be great to
have an expert's opinion on how to solve this best:
a) keep track manually on left items when deleting node_A which means
"somehow" in Java delete node_B as soon as we detect there are no more
relationships left...
b) create a batch job which frequently (daily or sth like this) checks
and removes our graph for lonely nodes...
c) maybe there is a SDN annotation preventing us from using option a)
or b)

Thanks for your help,
Florian...

Michael Hunger

unread,
Feb 8, 2012, 3:11:00 AM2/8/12
to ne...@googlegroups.com
Cascading delete is tricky in a graph b/c you easily get on deleting the whole graph by just deleting one node.

Many of the relationships are rather associations than contains-relationships so there the "dangling" node is the intended outcome.

I would create service methods around use-cases where the use-case specifies what has to be deleted and how far into the graph.

Then you can for instance write a single cypher query that returns all the nodes that should be deleted and you can delete them in one loop. (Could even be generified into template.deleteAll(String query) ).

So as there is already repository.delete(Iterable) so there should probably also be a similar method on template.

So it is just a one-liner to implement a cascading delete which is usecase specific and not generic and leads to annotation configuration hell.

One could also imagine having @Query annotated methods on repositories like @Query(...) public long deleteXX()

Michael

Reply all
Reply to author
Forward
0 new messages