Java Spring Neo4jRepository unable to read a property of abstract type

Viewed 24

I have just started experimenting with Neo4J/Java and expect this is an easy one I'm missing, and probably phrasing my queries wrong.

I have some model classes as follows:

@Node
public class Garment {

    @Id
    @GeneratedValue
    private Long id;

    private String name;

    @Relationship(type = "DESIGNED_BY")
    private Entity designer;

    // Other properties getters/setters removed for readibility

    public Entity getDesigner() {
        return designer;
    }

    public void setDesigner(Entity designer) {
        this.designer = designer;
    }
}

public abstract class Entity {

    @Id
    @GeneratedValue
    Long id;

    private String name;

    public Long getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}

@Node
public class Person extends Entity {
}

@Node
public class Company extends Entity {
}

And a corresponding repository

public interface Garment extends Neo4jRepository<Garment, Long> {

    Garment findByName(String name);
}

I have no problem inserting, using repository.save(), this correctly adds everything; nodes, relationships. Fine. It gives Designers of type Person labels of Person, and Designers of type Company the label Company.

However, when I do a find, e.g. findByName(), findAll(). it is not matching the designer and just saying designer is null, according to the cipher being executed/logged it looks like it's trying to build a relationship there with nodes with an Entity label, which there are none.

How can I get my repository to return Garments with designers of Person and Companys. I expect this is going to be as simple as an annotation, in order to fix.

(Note I've tried adding a @Node on the entity type with Person and Company as labels, however it just results in every node being added as both a Person and a Company).

0 Answers
Related