Search code examples
javaneo4jcypherneo4j-ogm

Neo4J OGM Session.load(ID) returns null object for existing ID


I am conducting some Neo4J tests and running into the following peculiar problem. I created a small model which I'm intending to use with OGM. The model has a superclass Entity and a child class Child. They're both in package persistence.model. Entity has the required Long id; with matching getId() getter.

public abstract class Entity {
   private Long id;
   public Long getId() {
      return id;
   }
}

@NodeEntity
Child extends Entity {
   String name;
   public Child() {
   }
}

Creating Child objects and persisting them through OGM works fine. I'm basing myself on the examples found in the documentation and using a Neo4jSessionFactory object, which initialises the SessionFactory with the package persistence.model. The resulting database contains objects with proper ID's filled in.

The problem arises when I try to fetch a Child for a given ID. I'm trying it with three methods, using two connection systems (bolt and ogm):

boltSession.run("MATCH (a:Child) WHERE id(a) = {id} RETURN a", parameters("id", childId));

ogmSession.query("MATCH (a:Child) WHERE id(a) = $id RETURN a", params);

ogmSession.load(Child.class, childId, 1);

The first two methods actually return the correct data. The last one returns a null value. The last one, using OGM, has some obvious benefits, and I'd love to be able to use it properly. Can anyone point me in the right direction?


Solution

  • In your test code you are doing a lookup by id of type int.

    private int someIdInYourDatabase = 34617;
    

    The internal ids in Neo4j are of type Long.

    If you change the type of the id to long or Long then it will work.

    private long someIdInYourDatabase = 34617;