Search code examples
neo4jspring-data-neo4jneo4j-ogm

SDN parameterize RelationshipEntity type


In order to create RelationshipEntity I have to use the following construction:

@RelationshipEntity(type = "PLAYED_IN")
public class Role {
    @Id @GeneratedValue   private Long relationshipId;
    @Property  private String title;
    @StartNode private Actor actor;
    @EndNode   private Movie movie;
}

I have a question - is it possible to parameterize the RelationshipEntity type? Right now in the example above we have hard-coded PLAYED_IN type but I need to use many other types, like for example DIRECTOR_IN, WRITER_IN and so on. How to achieve it with SDN without introducing the separate RelationshipEntity classes for this purpose?

One possible solution is to define the job type as RelationshipEntity property but I'm not sure it is a good idea because I have ~30 millions of entities and AFAIK Neo4j doesn't support indexes on RelationshipEntity properties... Please advise.


Solution

  • How about relying on an abstract class with the common basics and inherit each necessary Role from it?

    abstract class BaseRelationship {
      @Id
      @GeneratedValue
      private Long relationshipId;
    
      @Property  
      private String title;
    
      [...]
    }
    

    and

    @RelationshipEntity(type = "PLAYED_IN")
    public class Role extends BaseRelationship {
      [...]
    }