Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Using enum RelationshipType with Neo4j?

I would like to define some relationship type between some typed node. When I look example always they use a String to define relationship type, as in this example . By using:

@RelationshipEntity(type = "ACTED_IN")

I tried to use org.neo4j.graphdb.RelationshipType but RelationshipEntity.type expect 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;
    }
}

RelationshipType enum provide a method "name()" what to do with ?

I do not like free text way, is it possible use an enum ?

Any full example will be appreciated.

Regards

like image 343
bioinfornatics Avatar asked Jan 27 '26 05:01

bioinfornatics


1 Answers

You can't due to the way annotations work. What you could do is declaring the relation names as constants.

interface RelationNames{
  String ACTED_IN = "ACTED_IN";
}

And then use those constants in your code

@RelationshipEntity(type = RelationNames.ACTED_IN)
like image 92
Sleiman Jneidi Avatar answered Jan 29 '26 18:01

Sleiman Jneidi