Question

I am new to AgentSpring and Neo4j, and I just went through a sample. Now I am wondering how to define a relationship between two nodeEntities.

For a node entity, we can use:

@RelatedTo(type="TEAMMATE", direction=Direction.BOTH)
public @Fetch Set<Person> teammates;

But how can I add more attributes to this teammate relationship? Something like when they begin to be teammates.

I saw there is a class @RelationshipEntity, but I do not know how to get @RelatedTo and @RelationshipEntity connected.

Was it helpful?

Solution

You would use @RelatedToVia instead and use a @RelationshipEntity as component type of your set (or your single field type).

@RelationshipEntity(type="TEAMMATE")
class Collaboration {
   @StartNode Person p1;
   @EndNode Person p2;
   Date start;
   Date end;
}

@RelatedToVia(type="TEAMMATE", direction=Direction.BOTH)
public Set<Collaboration> teammates;

See also the documentation at: http://docs.spring.io/spring-data/data-neo4j/docs/3.1.0.RC1/reference/htmlsingle/#d0e1915

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top