具有OGM

时间:2019-04-16 17:50:12

标签: java neo4j-ogm

最近从neo4j开始,然后将程序转换为使用OGM。已经能够将所有内容保存到数据库中,但是在进行检索时,在这种情况下,OGM似乎对节点类型和关系感到困惑:

(位置)<--- [访问] ---(人)--- [对应​​] --->(位置)

当我执行get()。load(Person.class,id,1)时,我得到了Person和CLOTHING节点很好,但是只有VISITED附加到了返回的Person节点上,并且我的对应组为null

在数据库中,基于浏览器中的查看,两个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);
    }
}

0 个答案:

没有答案