Reputation: 760
I've got an arbitrary depth tree of nodes which I'd like to delete.
I'd expected this to work:
MATCH (a)<-[rels*]-(t)
WHERE ID(a)=135
FOREACH(r in rels | DELETE r)
DELETE t,a
but it fails:
javax.transaction.HeuristicRollbackException: Failed to commit transaction
Transaction(32, owner:"qtp1200654940-73")
[STATUS_NO_TRANSACTION,Resources=1], transaction rolled back --->
Node record Node[137,used=false,rel=347,prop=-1,labels=Inline(0x0:
[]),light] still has relationships
Why is this? Shouldn't the relationships be removed first? I imagine that it's iterating over all the found paths and processing the shortest ones first.
Has anyone got an idea of how to work around this?
Upvotes: 1
Views: 878
Reputation: 66999
The a
node may have outgoing relationships, and any of the t
nodes may also have incoming/outgoing relationships not in the path leading to a
. Your query does not delete such relationships.
This query should delete the same nodes that your query attempted to delete, but it should also delete all the relationships that need to be deleted to allow that:
MATCH ()<-[r1*0..1]-(a)<-[rels*]-(t)-[r2*0..1]-()
WHERE ID(a)=135
FOREACH (x IN r1 | DELETE x)
FOREACH (x IN r2 | DELETE x)
FOREACH (x IN rels | DELETE x)
DELETE a, t
Upvotes: 3