I need some advice to give name to relationships. Plus, I'm not sure on how I have to annotate my domain entities with spring data. Most of examples that I've seen are unidirectional and the name chosen are pretty straightforward.
Supose the following example:
@NodeEntity
public class Person {
@Indexed
private String name;
@RelatedTo(type="OWNS", direction=Direction.OUTGOING)
private Set<Car> cars;
}
The relationship name seems ok, no problem.
Now suppose that I want to make this relationship bidirectional. What are the differences (and the pros/cons) of the following approaches.
1) Make both sides of the relationship direction=Direction.BOTH and call the relationship type="OWNERSHIP"?
@NodeEntity
public class Person {
@Indexed
private String name;
@RelatedTo(type="OWNERSHIP", direction=Direction.BOTH)
private Set<Car> cars;
}
@NodeEntity
public class Car {
@Indexed
private String description;
@RelatedTo(type="OWNERSHIP", direction=Direction.BOTH)
private Person person;
}
2) Use direction on both sides?
@NodeEntity
public class Person {
@Indexed
private String name;
@RelatedTo(type="OWNS", direction=Direction.OUTGOING)
private Set<Car> cars;
}
@NodeEntity
public class Car {
@Indexed
private String description;
@RelatedTo(type="OWNED_BY", direction=Direction.INCOMING)
private Person person;
}