Search code examples
neo4jcypherspring-data-neo4j-4

Neo4j Spring Data Neo4j 4 cascade delete


In my Neo4j/SDN4 project I have a complex hierarchy of node entitles with a many linked object of a different types. I'm working on Like/Dislike functionality and every node in my system can have associated list of Like objects.

Right now I'm working on the delete query. The issue is that if I'm going to delete a root node of a big hierarchy, I have to find Like nodes associated with every type of the nodes in this structure and delete them separately.

So, I just wondering is there in Neo4j/SDN 4 an option.. something like cascade delete in RDBMS systems that can be used for this purpose in order to avoid a huge Cypher query ?


Solution

  • Cascade delete is not available at the moment in neoj4-ogm/SDN (March 2017).

    See a feature request in github https://github.com/neo4j/neo4j-ogm/issues/273

    Your best option with SDN is to create a custom repository query that will delete both Like nodes and the root node:

    @Query("MATCH (e:Entity)-[r]-(like) " +
           "WHERE e.prop = {prop} " +
           "DELETE e,r,like"
    void deleteEntity(@Param("prop") String prop);