2

I am always getting null from the annotated @Relationship field (from neo4j ogm). Below is my simplified class implementation.

@NodeEntity
public class A {
    @Id @GeneratedValue private Long id;
    @Relationship(type = "HAS") private Set<B> mB;

    public Set<B> getB() {
        return mB;
    }
}

@NodeEntity
public class B {
    @Id @GeneratedValue private Long id;
    @Relationship(type = "HAS", direction = Relationship.INCOMING)
    private A mA;
}

This is how I created my graph

CREATE (a:A), (b1:B), (b2:B)
CREATE (a)-[:HAS]->(b1), (a)-[:HAS]->(b2) 

When I called getB(), it returned null. I can get all B instances from the graph using query as below

MATCH (:A)-[:HAS]->(b:B) RETURN b

The project was set up by spring-boot with neo4j, and I had those controller, domain, repository and service working. I could do some simple API calls to the server to get those attributes of class A or B (which I did not list above). It was just that I could not get this mB value. Any step I missed out to do?

Da_Pz
  • 698
  • 5
  • 13

0 Answers0