1

Spring Data Neo4j 4.0.0 中的节点自动获取有一个奇怪的问题。我有一个像下面这样的课程:

@NodeEntity
public class FilterVersionChange extends UnitVersion {
    @GraphId
    private Long id;

    public FilterVersionChange() {
        super();
    }

    public FilterVersionChange(String description, Long creationDate)
    {
        super(description, creationDate);
    }

    @Relationship(type="CONTAINS", direction = Relationship.OUTGOING)
    private Set<FilterState> filterStates;

    @Relationship(type="REFERENCES", direction = Relationship.OUTGOING)
    private FilterVersionChange referencedFilterVersionChange;

    @Relationship(type="ADDED", direction = Relationship.OUTGOING)
    private Set<FilterState> newFilterStates;

    @Relationship(type="DELETED", direction = Relationship.OUTGOING)
    private Set<FilterState> deletedFilterStates;

    @Relationship(type="MODIFIED", direction = Relationship.OUTGOING)
    private Set<ModifiedUnitState> modifiedFilterStates;

    @Relationship(type="TRACKS", direction = Relationship.INCOMING)
    private FilterVersion filterVersion;

    @Relationship(type = "CREATED_ON", direction = Relationship.OUTGOING)
    private TimeTreeSecond timeTreeSecond;

    public void createdOn(TimeTreeSecond timeTreeSecond) {
        this.timeTreeSecond = timeTreeSecond;
    }

    public void contains(Set<FilterState> filterStates) {
        this.filterStates = filterStates;
    }

    public void references(FilterVersionChange referencedFilterVersionChange) {
        this.referencedFilterVersionChange = referencedFilterVersionChange;
    }

    public void added(Set<FilterState> newFilterStates) {
        this.newFilterStates = newFilterStates;
    }

    public void deleted(Set<FilterState> deletedFilterStates) {
        this.deletedFilterStates = deletedFilterStates;
    }

    public void modified(Set<ModifiedUnitState> modifiedFilterStates) {
        this.modifiedFilterStates = modifiedFilterStates;
    }

    public void trackedIn(FilterVersion filterVersion) {
        this.filterVersion = filterVersion;
    }

    public FilterVersion getFilterVersion() {
        return filterVersion;
    }

    public Set<FilterState> getFilterStates() {
        return filterStates;
    }
}

在数据库中,我有一个 FilterVersionChange 节点,其中有几个 FilterStates 节点通过“CONTAINS”和“ADDED”关系连接到它。假设我有那个 FilterVersionChange 节点的 id,我想通过调用 findOne(id) 来获取该节点。但是,我从中得到的是 filterStates 变量的空值。

正如我从文档中了解到的那样, findOne 应该默认检索深度 1 。但我真的不知道为什么我用 filterStates 变量得到 null 的值。

提前感谢您,您的建议将不胜感激!

编辑

这是插入代码所在的函数。

public FilterVersionChange createNewFilterVersionChange(String projectName,
                                                        String filterVersionName,
                                                        String filterVersionChangeDescription,
                                                        Set<FilterState> filterStates)
{
    Long filterVersionNodeId = filterVersionRepository.findFilterVersionByName(projectName, filterVersionName);
    if(filterVersionNodeId != null)
    {
        FilterVersion newFilterVersion = filterVersionRepository.findOne(filterVersionNodeId, 2);
        HashMap<String, Filter> filterHashMap = new HashMap<String, Filter>();
        Iterable<Filter> filters = filterRepository.findAll();
        if(filters.iterator().hasNext())
        {
            for(Filter filter : filters)
            {
                filterHashMap.put(filter.getMatchingString(), filter);
            }
        }

        for(FilterState filterState : filterStates)
        {
            Filter filter;
            if(filterHashMap.isEmpty() == false)
            {
                 filter = filterHashMap.get(filterState.getMatchingString());
            }
            else
            {
                filter = new Filter(filterState.getMatchingString(), filterState.getMatchingType());
                filter.belongsTo(newFilterVersion.getProject());
            }
            filterState.stateOf(filter);
        }

        Date now = new Date();
        FilterVersionChange filterVersionChange = new FilterVersionChange();
        filterVersionChange.setDescription(filterVersionChangeDescription);
        filterVersionChange.setCreationDate(now.getTime());
        filterVersionChange.contains(filterStates);
        filterVersionChange.added(filterStates);
        filterVersionChange.trackedIn(newFilterVersion);
        TimeTreeSecond timeInstantNode = timeTreeService.getFilterTimeInstantNode(projectName, now.getTime());
        filterVersionChange.createdOn(timeInstantNode);
        FilterVersionChange addedFilterVersionChange = filterVersionChangeRepository.save(filterVersionChange);

        return addedFilterVersionChange;
    }
    else
    {
        return null;
    }
}

这是 FilterState 类

@NodeEntity
public class FilterState {

    @GraphId
    private Long id;

    private String matchingString;
    private String matchingType;

    public FilterState() {

    }

    public FilterState(String matchingString, String matchingType) {
        this.matchingString = matchingString;
        setMatchingType(matchingType);
    }

    @Relationship(type="STATE_OF", direction = Relationship.OUTGOING)
    private Filter filter;

    @Relationship(type="PART_OF", direction = Relationship.OUTGOING)
    private CodeUnit codeUnit;

    @Relationship(type="CONTAINS", direction = Relationship.INCOMING)
    private FilterVersionChange containedInFilterVersionChange;

    @Relationship(type="ADDED", direction = Relationship.INCOMING)
    private FilterVersionChange addedInFilterVersionChange;

    public void setMatchingString(String matchingString) {
        this.matchingString = matchingString;
    }

    public void setMatchingType(String matchingType) {
        String type = null;
        if(matchingType.equalsIgnoreCase("RegexFilter"))
        {
            type = "RegexFilter";
        }
        else if(matchingType.equalsIgnoreCase("ClassFilter"))
        {
            type = "ClassFilter";
        }
        this.matchingType = type;
    }

    public void stateOf(Filter filter) {
        this.filter = filter;
    }

    public void partOf(CodeUnit codeUnit) {
        this.codeUnit = codeUnit;
    }

    public String getMatchingString() {
        return matchingString;
    }

    public String getMatchingType() {
        return matchingType;
    }

    public Filter getFilter() {
        return filter;
    }

    public Long getId() {
        return id;
    }

    public void addedIn(FilterVersionChange addedInFilterVersionChange) {
        this.addedInFilterVersionChange = addedInFilterVersionChange;
    }

    public FilterVersionChange getContainedInFilterVersionChange() {
        return containedInFilterVersionChange;
    }
}

这是gradle文件

def RMQVersion = "3.3.4"
def GSONVersion = "2.3.1"

def Neo4jVersion = "2.2.1"
def Neo4jTimeTreeVersion = "2.2.1.30.21"

def SpringVersion = "4.1.6.RELEASE"
def SDNVersion = "4.0.0.BUILD-SNAPSHOT"

def JunitVersion = "4.12"

apply plugin: 'java'
apply plugin: 'maven'

sourceCompatibility = 1.5
version = '1.0'

repositories {
    mavenCentral()
    maven {
        url("http://maven.springframework.org/milestone")
    }
    maven {
        url("http://repo.spring.io/libs-snapshot")
    }
}

dependencies {
    compile "org.springframework.data:spring-data-neo4j:${SDNVersion}"

    compile "org.neo4j:neo4j:${Neo4jVersion}"
    compile "com.graphaware.neo4j:timetree:${Neo4jTimeTreeVersion}"

    compile "com.rabbitmq:amqp-client:${RMQVersion}"
    compile "com.google.code.gson:gson:${GSONVersion}"

    testCompile group: 'org.springframework.data', name: 'spring-data-neo4j', version: SDNVersion, classifier: 'tests'
    testCompile group: 'org.springframework', name: 'spring-test', version: SpringVersion
    testCompile group: 'junit', name: 'junit', version: JunitVersion
}
4

1 回答 1

3

此问题已在 4.0.0M1 后修复,请使用最新的构建快照,谢谢。

于 2015-05-22T04:12:35.023 回答