Neo4j 3.0.1 SDN 4.1.1.RELEASE 幻影节点

Neo4j 3.0.1 SDN 4.1.1.RELEASE phantom nodes

在我的 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);

它returns 为空。到目前为止一切顺利。

在那之后,我试图从 Criterion 中获取组对象,它位于已删除的 CriterionGroup 中,它 returns.. 已删除 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<>();

他们有不同的方向。

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

刷新整个会话

是的,有 CONTAINS 关系定义是可以的,请记住,对于任何标记为 INCOMING 的关系,如果它们存在 [=],则必须注释 parentDecisions 的访问器、修改器和属性14=]

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