From 4dbc1e11423359a0b5809041af103f8b105ac5f0 Mon Sep 17 00:00:00 2001 From: yaxin Date: Fri, 10 Jan 2025 09:17:04 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=9E=E9=80=80=E5=88=A0=E9=99=A4CYPHER?= =?UTF-8?q?=EF=BC=8C=E5=BD=93=E8=8A=82=E7=82=B9=E6=9C=89=E5=A4=9A=E6=9D=A1?= =?UTF-8?q?=E8=BE=B9=E6=97=B6=EF=BC=8C=E5=88=A0=E9=99=A4=E6=8A=9B=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=98=AF=E6=9C=9F=E6=9C=9B=E7=BB=93=E6=9E=9C=EF=BC=8C?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E4=BD=BF=E7=94=A8detach=E7=9B=B4=E6=8E=A5?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../supervision/neo4j/service/impl/Neo4jServiceImpl.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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); } }