Несколько типов отношений между двумя узлами с OGM - PullRequest
0 голосов
/ 16 апреля 2019

Недавно начал с neo4j и конвертировал программу в использование OGM. Я смог получить все, что было сохранено в базе данных, но при извлечении OGM запутывается в типах узлов и отношениях в этом случае:

(МЕСТОПОЛОЖЕНИЯ) <--- [ПОСЕТИЛ] --- (человек) --- [переписывался] ---> (МЕСТОПОЛОЖЕНИЕ)

Когда я выполняю свой get (). Load (Person.class, id, 1), я получаю узлы Person и CLOTHING просто отлично, но только VISITED присоединен к возвращенному узлу Person, и мой CORRESPONDED набор равен нулю. .

В базе данных, основанной на просмотре в браузере, оба узла LOCATION созданы и имеют правильные отношения с ними.

@NodeEntity
public class Person extends Entity {

    @Relationship(type = RelationshipTypes.CLOTHINGREL)
    private Set<Clothing> clothing;

    @Id
    private String id;

    @Relationship(type = RelationshipTypes.VisitedLocationREL)
    private Set<LocationVisited> LocationVisiteds;

    @Relationship(type = RelationshipTypes.CorrespondedLocationREL)
    private Set<LocationCorresponded> LocationCorrespondeds;

    private String name;
    private String gender;

    public Person() {
    }

    public Person(@JsonProperty(value = "id") String id,                 
                  @JsonProperty(value = "name") String name,
                  @JsonProperty(value = "gender") List<String> gender,
    ) {
        this.id = id != null ? id : "";
        this.name = name != null ? name : "";      
        this.gender = gender != null ? gender.get(0) : "";

        this.clothing = new HashSet<>();
        this.LocationVisiteds = new HashSet<>();
        this.LocationCorrespondeds = new HashSet<>();       
    }


    public void addClothing(Clothing cloth) {
        this.clothing.add(cloth);
    }

    public void addLocationCorresponded(LocationCorresponded dc) {
        this.LocationCorrespondeds.add(dc);
    }

    public void addLocationVisited(LocationVisited dd) {
        this.LocationVisiteds.add(dd);
    }
}

@NodeEntity
public abstract class Location extends Entity {

    @Id
    private String Location;

    Location(@JsonProperty(value = "Location") String Location) {
        this.Location = Location != null ? Location : "";
    }

    Location() {
    }

    public void addPerson(Person person) {
    }
}

@NodeEntity(label = "Location")
public class LocationVisited extends Location {
    @Relationship(type = RelationshipTypes.VisitedLocationREL, direction = Relationship.INCOMING)
    Set<Person> persons;

    LocationVisited(@JsonProperty(value = "Location") String Location) {
        super(Location);
        this.persons = new HashSet<>();
    }

    LocationVisited() {
    }

    public void addPerson(Person person) {
        this.persons.add(person);
    }
}

@NodeEntity(label = "Location")
public class LocationCorresponded extends Location {
    @Relationship(type = RelationshipTypes.CorrespondedLocationREL, direction = Relationship.INCOMING)
    Set<Person> persons;

    LocationCorresponded(@JsonProperty(value = "Location") String Location) {
        super(Location);
        this.persons = new HashSet<>();
    }

    LocationCorresponded() {
    }

    public void addPerson(Person person) {
        this.persons.add(person);
    }
}

...