Search code examples
neo4jspring-data-neo4jneo4j-ogm

How to use Spring data neo4j-RX to support multiple labels in a node


Can some one help me on how to use Spring data neo4j-RX JPA to support multiple labels in a node.

Suppose I have a below node in neo4j database

(:Person:Male {name:"ABC"])

How to convert above node with multiple labels to equivalent entity in Java with neo4j-RX JPA?


Solution

  • You can define multiple labels in the @Node annotation on your entity.

    For example:

    @Node("Person","Male")
    public class MalePerson {}
    

    Another option is to use inheritance:

    @Node
    public class Person {}
    
    @Node
    public class Male extends Person {}
    

    This would not apply to your use-case but I also add the third option here: Dynamic Labels

    @Node
    public class Person {
      @DynamicLabels
      private List<String> labels; // here you would add Male
    }
    

    On a side note: Spring Data Neo4j RX (or now Spring Data Neo4j 6) is not a JPA implementation.