diff --git a/src/main/java/com/supervision/neo4j/service/impl/Neo4jServiceImpl.java b/src/main/java/com/supervision/neo4j/service/impl/Neo4jServiceImpl.java index 77c9327..b6d5d95 100644 --- a/src/main/java/com/supervision/neo4j/service/impl/Neo4jServiceImpl.java +++ b/src/main/java/com/supervision/neo4j/service/impl/Neo4jServiceImpl.java @@ -92,13 +92,14 @@ public class Neo4jServiceImpl implements Neo4jService { try { Session session = driver.session(); StringBuilder cql = new StringBuilder(); - cql.append("MATCH (n) where id(n) = ").append(id).append(" DETACH DELETE n"); + cql.append("MATCH (n) where id(n) = ").append(id).append(" DELETE n"); log.info(cql.toString()); Result run = session.run(cql.toString()); while (run.hasNext()) { run.next(); } } catch (Exception e) { + //如果报错,说明存在未删除的关系,是合理的 log.error(e.getMessage(), e); } } @@ -108,13 +109,14 @@ public class Neo4jServiceImpl implements Neo4jService { try { Session session = driver.session(); StringBuilder cql = new StringBuilder(); - cql.append("MATCH (n) WHERE id(n) = ").append(id).append(" DETACH DELETE n"); + cql.append("MATCH (n) WHERE n.id = ").append(id).append(" AND NOT (n)--() DELETE n"); log.info(cql.toString()); Result run = session.run(cql.toString()); while (run.hasNext()) { run.next(); } } catch (Exception e) { + //如果报错,说明存在未删除的关系,是合理的 log.error(e.getMessage(), e); } }