首页 > 解决方案 > Set类型的可变深度持久性和关系

问题描述

我有以下关系

图 -has-many- Connection Connection -has-many MoveablePoints

我正在使用 neo4j 的 neo4j omg 存储库接口 v3.1.3 来持久添加和删除连接和可移动点。我的单元测试工作正常,但是如果我在 Web 环境中使用它,则不会应用连接的删除。

我正在使用 5 的可变深度持久性。我觉得这与 omg 会话有关,但我不确定。任何想法都会受到欢迎。

服务代码

@Transactional
    @Override
    @Retryable(value = TransientException.class,exceptionExpression="#{message.contains('RWLock')}", maxAttempts = 5)
    public Diagram update(Diagram diagram) throws GUMLException {

//        for (Connection connection : diagram.getConnections())
//            if (connection.getId() != null)
//                connectionService.deleteMoveablePoints(connection.getId());
//
//        for (DiagramElement de : diagram.getDiagramElements()) {
//            diagramElementService.save(de);
//        }


        return umlDiagramRepository.save(diagram, 5);

    }

领域类

@NodeEntity
public class Diagram {
   public Set<Connection> getConnections() {
        if (connections == null)
            connections = new HashSet<Connection>();
        return connections;
    }

    public void setConnections(Set<Connection> connections) {
        this.connections = connections;
    }

    @org.neo4j.ogm.annotation.Relationship(type = "HasConnections", direction = org.neo4j.ogm.annotation.Relationship.OUTGOING)
    Set<Connection> connections;

}

@NodeEntity
public class Connection implements IConnector {
  public Set<MoveablePoint> getMoveablePoints() {
        return moveablePoints;
    }

    public void setMoveablePoints(Set<MoveablePoint> moveablePoints) {
        this.moveablePoints = moveablePoints;
    }


    @org.neo4j.ogm.annotation.Relationship(type = "HasMoveablePoints", direction = org.neo4j.ogm.annotation.Relationship.OUTGOING)
    private Set<MoveablePoint> moveablePoints;

}

当我更改我的服务代码以首先从会话中检索对象然后覆盖时,它似乎可以工作。不过,这对我来说似乎不对。

Diagram d2 = umlDiagramRepository.findById(diagram.getId()).get();
        d2 = diagram;

        return umlDiagramRepository.save(d2, 5);

标签: neo4jpersistencerelationshipneo4j-ogm

解决方案


推荐阅读