Neo4j 3.0.1 SDN 4.1.1.RELEASE幻像节点

时间:2016-05-24 20:48:31

标签: neo4j cypher spring-data-neo4j spring-data-neo4j-4 neo4j-ogm

在我的Neo4j 3.0.1SDN 4.1.1.RELEASE项目中,我有以下实体:

@NodeEntity
public class CriterionGroup extends Authorable {

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

    private String name;

    private String description;

    @Relationship(type = DEFINED_BY, direction = Relationship.OUTGOING)
    private Decision owner;

    @Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
    private Set<Criterion> criteria = new HashSet<>();
....

@NodeEntity
public class Criterion extends Authorable {

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

    private String name;

    private String description;

    @Relationship(type = CONTAINS, direction = Relationship.INCOMING)
    private CriterionGroup group;

    @Relationship(type = DEFINED_BY, direction = Relationship.OUTGOING)
    private Decision owner;
....


@NodeEntity
public class Decision extends Commentable {

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

    private String name;

    @Relationship(type = CONTAINS, direction = Relationship.INCOMING)
    private Set<Decision> parentDecisions = new HashSet<>();

    @Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
    private Set<Decision> childDecisions = new HashSet<>();

    @Relationship(type = DEFINED_BY, direction = Relationship.INCOMING)
    private Set<CriterionGroup> criterionGroups = new HashSet<>();

    @Relationship(type = DEFINED_BY, direction = Relationship.INCOMING)
    private Set<Criterion> criteria = new HashSet<>();
....

在我的测试中,我尝试使用以下存储库方法删除CriterionGroup

@Query("MATCH ()-[r]-(cg:CriterionGroup) WHERE id(cg) = {criterionGroupId} DELETE cg, r")
void deleteCriterionGroup(@Param("criterionGroupId") Long criterionGroupId);

然后我试图通过id

获取此CriterionGroup
criterionGroupRepository.findOne(id);

并返回NULL。到目前为止一切都很好。

之后,我正在尝试从已删除的Criterion中的CriterionGroup获取组对象,并返回..已删除CriterionGroup

criterionRepository.findOne(criterion.getId()).getGroup()

我做错了什么?一切都在SDN 3.4.4.RELEASENeo4j 2.3.3上工作正常,但Neo4j 3.0.1 SDN 4.1.1.RELEASE由于我的知识有限,我有很多意想不到的情况。

此外,在一个实体中有以下关系定义是否可以(我已删除enforceTargetType

@Relationship(type = CONTAINS, direction = Relationship.INCOMING)
private Set<Decision> parentDecisions = new HashSet<>();

@Relationship(type = CONTAINS, direction = Relationship.OUTGOING)
private Set<Decision> childDecisions = new HashSet<>();
他们有不同的指示。

1 个答案:

答案 0 :(得分:2)

据我所知,您重新出现此CriterionGroup是因为您通过自定义查询删除了它,从而绕过了OGM。图表知道您的更改,但OGM的映射上下文不知道。 解决方案是在使用Session.detachEntity(id)通过自定义查询删除此实体后,从会话中注销该实体,或者使用session.clear()刷新整个会话。

是的,可以使用CONTAINS关系定义,请记住,对于标记为INCOMING的任何关系,如果parentDecisions存在,则必须为@Relationship(type = CONTAINS, direction = Relationship.INCOMING)注释访问者,变更器和属性}

更新:还要确保您的对象模型与您通过自定义查询删除的内容保持同步。即如果您通过自定义查询删除CriterionGroup,您还应该更新对象模型以反映这一点criterion.group=null。或者,使用session.clear()完全清除会话并重新加载所有相关实体。