Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring 未删除SDN关系_Spring_Neo4j_Spring Data_Spring Data Neo4j - Fatal编程技术网

Spring 未删除SDN关系

Spring 未删除SDN关系,spring,neo4j,spring-data,spring-data-neo4j,Spring,Neo4j,Spring Data,Spring Data Neo4j,我想使用spring-data-neo4j在neo4j中实现一个时间树。 下图显示了时间树,它当前仅包含根节点(223)以及2016年和2018年 如果我现在添加2017,我希望结果2016-[:下一个]->2017->[:下一个]->2018以及2016和2018之间的下一个关系被删除 这应该通过根节点的createChild方法实现: public TimeNode createChild(int value) { TimeNode newChild = new Year();

我想使用spring-data-neo4j在neo4j中实现一个时间树。 下图显示了时间树,它当前仅包含根节点(223)以及2016年和2018年

如果我现在添加2017,我希望结果2016-[:下一个]->2017->[:下一个]->2018以及2016和2018之间的下一个关系被删除

这应该通过根节点的createChild方法实现:

public TimeNode createChild(int value) {
    TimeNode newChild = new Year();
    newChild.setValue(value);

    if (!this.hasChildren()) {
        this.setFirstChild(newChild);
        this.setLastChild(newChild);
    } else if (this.getFirstChild().getValue() > value) {
        //new node is first child
        newChild.setNextNode(this.getFirstChild());
        this.setFirstChild(newChild);
    } else if (this.getLastChild().getValue() < value) {
        //new node is last child
        newChild.setPreviousNode(this.getLastChild());
        this.setLastChild(newChild);
    } else {
        TimeNode previous = this.getFirstChild();
        TimeNode next = this.getLastChild();
        for (TimeNode current : this.getChildren()) {
            if (current.getValue() < value){
                if (current.getValue() > previous.getValue()) previous = current;
            }
            else if (current.getValue() < next.getValue()) next = current;
        }
        System.out.println("Previous is "+previous.getValue());
        System.out.println("Next is "+next.getValue());
        newChild.setPreviousNode(previous);
        newChild.setNextNode(next);
    }
    this.addChild(newChild);
    return newChild;
}
创建新的子节点后,我调用

timeNodeRepository.save(foundYear,2);
在呼叫服务中。存储库是标准存储库

@Repository
public interface TimeNodeRepository extends GraphRepository<TimeNode> 

setPreviousNode反之亦然

如果您有一个您不期望的持久化关系,这通常是因为您的一个对象仍然持有对另一个对象的引用,而您在代码中没有意识到或没有考虑到这一点。在保存之前,您是否检查了链接列表的前后是否正确?我没有在那里执行检查,但是设置者应该处理这个问题。看起来,实体类会将相关注释映射到错误的方向,而不是将其保留为空,这可能吗?您可以添加配置和管理事务的方式吗?加载foundYear并保存它必须在1个事务内。当然,它发生在此服务中:
@Repository
public interface TimeNodeRepository extends GraphRepository<TimeNode> 
public void setNextNode(TimeNode nextNode) {
    this.nextNode=null;
    if (nextNode==null) return;
    nextNode.previousNode = this;
    this.nextNode = nextNode;
}