Skip to content

Commit 05295f2

Browse files
committed
chore: update edge to avoid duplicated creation
Signed-off-by: Otavio Santana <[email protected]>
1 parent 2b002b2 commit 05295f2

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

jnosql-neo4j/src/main/java/org/eclipse/jnosql/databases/neo4j/communication/DefaultNeo4JDatabaseManager.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,10 @@ public void edge(CommunicationEntity source, String label, CommunicationEntity t
235235
Objects.requireNonNull(label, "Relationship type is required");
236236

237237
String cypher = "MATCH (s) WHERE elementId(s) = $sourceElementId " +
238-
"MATCH (t) WHERE elementId(t) = $targetElementId " +
239-
"CREATE (s)-[r:" + label + "]->(t)";
238+
"MATCH (t) WHERE elementId(t) = $targetElementId " +
239+
"WITH s, t " +
240+
"WHERE NOT EXISTS { MATCH (s)-[r:" + label + "]->(t) } " +
241+
"CREATE (s)-[r:" + label + "]->(t)";
240242

241243
try (Transaction tx = session.beginTransaction()) {
242244
var sourceId = source.find(ID).orElseThrow(() ->

0 commit comments

Comments
 (0)