首页 > 解决方案 > SDN5:为 (14762)-[CONTAINS]->(14781) 找到多个匹配的 @RelationshipEntity,但无法确定使用哪一个

问题描述

我创建了两个@RelationshipEntity具有相同类型的不同 Spring Data Neo4j 5:

@RelationshipEntity(type = "CONTAINS")
public class CharacteristicRelationship {

    @Id
    @GeneratedValue
    private Long id;

    @StartNode
    private CharacteristicGroup characteristicGroup;

    @EndNode
    private Characteristic characteristic;

}

@RelationshipEntity(type = "CONTAINS")
public class DecisionGroupRelationship {

    @Id
    @GeneratedValue
    private Long id;

    @StartNode
    private Decision decision;

    @EndNode
    private DecisionGroup childGroup;

}

一切正常,我成功地通过了所有测试,但现在我在控制台中不断收到以下错误:

2018-04-29 15:36:52.387 ERROR 7664 --- [           main] org.neo4j.ogm.context.GraphEntityMapper  : Found more than one matching @RelationshipEntity for (14762)-[CONTAINS]->(14781) but cannot tell which one to use
2018-04-29 15:36:52.390 ERROR 7664 --- [           main] org.neo4j.ogm.context.GraphEntityMapper  : Found more than one matching @RelationshipEntity for (14762)-[CONTAINS]->(14779) but cannot tell which one to use
2018-04-29 15:36:52.391 ERROR 7664 --- [           main] org.neo4j.ogm.context.GraphEntityMapper  : Found more than one matching @RelationshipEntity for (14762)-[CONTAINS]->(14774) but cannot tell which one to use

我做错了什么以及如何解决?是否允许@RelationshipEntity相同类型的不同?

org.neo4j.ogm.context.GraphEntityMapper.getRelationshipEntity(Edge)我可以看到以下代码:

} else {
    // almost definitely a user bug
    logger.error("Found more than one matching @RelationshipEntity for {} but cannot tell which one to use",
    edge.toString());
 }

那只是打印错误日志,就是这样。从中真的很难理解 - 这是一个错误或否以及如何处理它。

课程:

@NodeEntity
public class CharacteristicGroup extends BaseEntity {

    private static final String DEFINED_BY = "DEFINED_BY";
    private static final String CONTAINS = "CONTAINS";

    @Index(unique = true)
    private Long id;

    @Index(unique = false)
    private String name;

    @Index(unique = false)
    private String lowerName;

    @Relationship(type = DEFINED_BY, direction = Relationship.OUTGOING)
    private Set<DecisionGroup> decisionGroups;

    @Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
    private Set<CharacteristicRelationship> characteristicRelationships;

...

}

@NodeEntity
public class Characteristic extends BaseEntity {

    private static final String CONTAINS = "CONTAINS";

    @Index(unique = true)
    private Long id;

    @Index(unique = false)
    private String name;

    @Index(unique = false)
    private String lowerName;

    @Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
    private Set<CharacteristicProperty> properties;

    @Relationship(type = CONTAINS, direction = Relationship.INCOMING)
    private Set<CharacteristicRelationship> characteristicRelationships;

...

}

@NodeEntity
public class DecisionGroup extends BaseEntity {

    private static final String CONTAINS_DECISION_GROUP = "CONTAINS_DECISION_GROUP";

    @Index(unique = true)
    private Long id;

    @Index(unique = false)
    private String name;

    @Index(unique = false)
    private String lowerName;

    @Relationship(type = CONTAINS_DECISION_GROUP, direction = Relationship.INCOMING)
    private Set<DecisionGroupRelationship> decisionGroupRelationships;

    @Index(unique = false)
    private int totalChildDecisions;

...

}

@NodeEntity
public class Decision extends BaseEntity {

    private static final String DEFINED_BY = "DEFINED_BY";
    private static final String CONTAINS = "CONTAINS";
    private static final String CONTAINS_DECISION_GROUP = "CONTAINS_DECISION_GROUP";
    public static final String FOLLOWS = "FOLLOWS";

    @Index(unique = true)
    private Long id;

    @Index(unique = false)
    private String name;

    @Index(unique = false)
    private String lowerName;

    @Relationship(type = CONTAINS, direction = Relationship.INCOMING)
    private Set<DecisionGroup> parentGroups;

    @Relationship(type = CONTAINS_DECISION_GROUP, direction = Relationship.OUTGOING)
    private Set<DecisionGroupRelationship> childGroupRelationships;

    @Relationship(type = DEFINED_BY, direction = Relationship.INCOMING)
    private Set<Media> medias;

    @Index(unique = false)
    private int totalViews;

...

}

@NodeEntity
public abstract class BaseEntity implements BaseEntityVisitable {

    private static final String CREATED_BY = "CREATED_BY";
    private static final String UPDATED_BY = "UPDATED_BY";
    private static final String OWNED_BY = "OWNED_BY";
    private static final String CONTAINS = "CONTAINS";

    @Id
    @GeneratedValue
    private Long graphId;

    @Index(unique = true)
    private String uuid;

    @Index(unique = true)
    private String customId;

    @DateLong
    @Index(unique = false)
    private Date createDate;

    @Relationship(type = CREATED_BY, direction = Relationship.OUTGOING)
    private User createUser;

    @DateLong
    @Index(unique = false)
    private Date updateDate;

    @Relationship(type = UPDATED_BY, direction = Relationship.OUTGOING)
    private User updateUser;

    @Relationship(type = OWNED_BY, direction = Relationship.OUTGOING)
    private Set<BaseEntity> ownerEntities;

    @Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
    private Set<Translation> translations;

...

}

标签: javaneo4jneo4j-ogmspring-data-neo4j-5spring-data-neo4

解决方案


推荐阅读