How to use Using enum RelationshipType with Neo4j?

I would like to define some type of relationship between some typed node. When I look at the example, they always use String to define the type of the relationship, as in this example . Using:

@RelationshipEntity(type = "ACTED_IN")

      

I tried using org.neo4j.graphdb.RelationshipType, but RelationshipEntity.type expects a string.

public enum PersonMovieRelationshipType implements RelationshipType {
    ACTED_IN("ACTED_IN"),
    AUTHOR("AUTHOR");

    private String type;

    PersonMovieRelationshipType( String type ){
        this.type = type;
    }

    public String getType() {
        return type;
    }
}

      

The RelationshipType enum variable provides a "name ()" method, what should I do with?

I don't like the free text way, is it possible to use an enum?

Any complete example would be appreciated.

Hello

+3


source to share


1 answer


You can't because of the work of annotations. What you could do is declare the names of the relations as constants.

interface RelationNames{
  String ACTED_IN = "ACTED_IN";
}

      



And then use these constants in your code

@RelationshipEntity(type = RelationNames.ACTED_IN)

      

+5


source







All Articles