Search code examples
javaneo4jcypherrelationshipneo4j-ogm

Neo4J with OGM dynamic @RelationshipEntity/@Relationship value


It´s possible to use a dynamic value for Relation Nodes? I would like to set different Relation make for each graph on Neo4j, I think this could increase the performance of Neo4j, but I would like to know if it´s possible to use OGM on Java with dynamic value for the relations.

Thanks a lot.


Solution

  • To create relationships with dynamic types you can install APOC Procedures and use the procedure apoc.create.relationship. This procedure creates relationships with dynamic relationship type.

    For example:

    with "REL_TYPE" as reltype
    match (n1:Node {id:1}), (n2:Node {id:2})
    call apoc.create.relationship(n1, reltype,{}, n2) yield rel
    return *
    

    will create a relationship -[:REL_TYPE]- between n1 and n2.

    With this approach you can pass the relationship type string as parameter to Neo4j in your Java application, then call apoc.create.relationship.