Neo4J OGM - session.save() 方法在从实体中删除关系时不会更新.main2 中的



session.save(( 方法不会更新连接的子节点。删除的节点"tn2"仍通过"tn1"与"to"连接。

Neo4J

3.1.0 和 Neo4J OGM 2.1.2 采用 Bolt 配置。

下面是代码示例;

@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) 
}

您很可能没有从两侧删除对"tn2"的引用。 to.getRn().remove("tn2")从 TestNode 中删除引用,但不会将其从 TestOrg 中删除。尝试添加to.setRn(null),它应该可以工作

最新更新