Spring Neo4J 4 Data - No .fetch () Template

I am trying to upgrade from Spring Data Neo4J 3 to 4 - I am using Neo4J 2.2.2.

I am using an instance of GraphRepository to query the database, get the object back.

This object has several relationships that are not retrieved (intentionally to avoid reading on the entire chart).

The SDN3 code just uses the Neo4JTemplate class to make a fetch call for every connection I needed to get. It worked very well.

However, in SDN4, this tool was removed and replaced by various implementations of the load () method. The documentation does not show how to achieve what I did in SDN3.

To be clear: if I have a set of objects in the first class that I retrieve, controlled by communication, I want to get only the objects in this set, and not the entire set of these objects in the database.

Am I missing something important during the upgrade process, or is there an easy way to do what I'm trying to do?

Adding code:

My entity class:

@NodeEntity
public class File implements MetroNode {

    private Long id;

    private String fileName;

    private SourceState sourceState;

    private Set<State> states;

    @GraphId
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    @Relationship(type = "HAS_FILE", direction = Relationship.INCOMING)
    public SourceState getSourceState() {
        return sourceState;
    }

    public void setSourceState(SourceState sourceState) {
        this.sourceState = sourceState;
    }

    public State addState(MetroNode otherNode, StateStatus status) {
        if (this.states == null) {
            this.states = new HashSet<State>();
        }
        State state = new State(this, otherNode, status.toString());
        this.states.add(state);
        return state;
    }

    @Relationship(type = "HAS_STATE", direction = Relationship.OUTGOING)
    public Set<State> getStates() {
        return states;
    }

    public State getActiveState() {
        if (this.states != null) {
            for (State state : this.states) {
                if (state.isActive()) {
                    return state;
                }
            }
        }
        return null;
    }

}

My repository class:

public interface FileRepository extends GraphRepository<File> {

    File findByFileName(String fileName);     
}

When the getActiveState () method is executed, I get a null return because the set of states is empty (was not selected).

Looking again at my code, I wonder, is it because I am not using the "native" method of loading from the repository, but the overloaded version?

+4
source share
1 answer

SDN 4 .

0 . 1 , ..

.

0

Source: https://habr.com/ru/post/1620092/


All Articles