Neo4j的。如何将已存储的实体存储其他参数?

时间:2015-08-26 07:37:58

标签: neo4j spring-data-neo4j

我需要Device\SoftwareEntityEntity的参数不同。 Device\Software将存储在数据库中,一旦新的Entity被创建,它将与已存储的某些Device\Software建立关系,但其参数可能会因不同的Entities而异(参数数量或其值。)

我尝试直接在图表的边缘保存其他参数(在RelationshipEntityEntity之间的Device\Software),但似乎在实施某些网络比较算法时会增加复杂性

有没有人有类似的情况?什么是最佳实践方法?

@NodeEntity
public class Entity {

    @GraphId
    protected Long id;
    protected String title;
    /**
     * More fields here 
     */

    @Fetch
    @RelatedTo(direction = Direction.BOTH, type = "has_devices")
    protected Set<Device> devices = new HashSet<>();

    @Fetch
    @RelatedTo(direction = Direction.BOTH, type = "has_software")
    protected Set<Software> software = new HashSet<>();
}


@NodeEntity
public class Device {

    @GraphId
    protected Long id;
    protected String identifier;
    /**
     * More fields here 
     */

    @Fetch
    @RelatedTo(direction = Direction.BOTH, type = "has_parameter")
    protected Collection<ParameterEntity> parameter = new HashSet<>();
}

@NodeEntity
public class Software {

    @GraphId
    protected Long id;
    protected String identifier;
    /**
     * More fields here 
     */

    @Fetch
    @RelatedTo(direction = Direction.BOTH, type = "has_parameter")
    protected Collection<ParameterEntity> parameter = new HashSet<>();
}

ParameterEntity只是键值对象。

1 个答案:

答案 0 :(得分:1)

不确定你的参数是什么意思。但是保存他们的关系应该有效。如果您不需要,可以忽略算法中的参数。

这实际上取决于你的参数只是量化关系,还是它们本身就是真实的实体。