Search code examples
javaneo4jspring-data-neo4jneo4j-ogm

Neo4j treating two different objects as one, because they extend the same parent


I currently have two objects which have a lot of common properties, so I created a parent object and moved all the common properties into the parent, however now when I look inside the neo database, it treats the parent as it's own object and makes all my nodes look like they're one type.

@NodeEntity
public class Cat extends Parent {
    private int legs;
}

@NodeEntity
public class Car extends Parent {
    private int wheels;
}

public class Parent {
    private int id;
    private Stirng name;
}

Solution

  • To avoid inheriting labels because of the class hierarchy, you can make Parent abstract, or an interface. Then, the Parent label will not be added to Cat and Car The rules for label inheritance can be read here: https://neo4j.com/docs/ogm-manual/current/reference/#reference:annotating-entities:node-entity