session.save()方法不更新连接的子节点。已移除的节点“tn2”仍通过“tn1”与“to”连接。
Neo4J 3.1.0和带螺栓配置的Neo4J OGM 2.1.2。
以下是代码示例;
@NodeEntity
public class TestOrg {
@GraphId
private Long id;
@Relationship(type="ROOT", Direction=Relationship.OUTGOING)
TestNode rn;
}
public class TestNode {
@GraphId
private Long id;
@Relationship(type="HAS", Direction=Relationship.OUTGOING)
List<TestNode> subs = new ArrayList<TestNode>();
//remove method: gets the name of the node and removes from the subs list.
}
main1{
TestNode tn1 = new TestNode();
tn1.setName("tn1");
TestNode tn2 = new TestNode();
tn2.setName("tn2");
TestNode tn3 = new TestNode();
tn3.setName("tn3");
tn1.addSub(tn2);
tn1.addSub(tn3);
TestOrg to = new TestOrg();
to.setName("to");
to.setRn(t1);
session.save(to);
}
main2{
...
//gets the id of the TestOrg with name "to" from db
TestOrg to = session.load(TestOrg.class, id, maxDepth);
to.getRn().remove("tn2");
session.save(to, maxDepth); //session.save(to)
}
答案 0 :(得分:0)
您很可能没有从双方删除“tn2”的引用。
to.getRn().remove("tn2")
从TestNode中删除引用,但没有任何内容从TestOrg中删除它。尝试添加to.setRn(null)
,它应该可以正常工作