Using spring -data-neo4j, I want to create two classes using @RelationshipEntity(type="OWNS") to associate the Person class with both Pet and Car .
@RelationshipEntity(type="OWNS") public class OwnsCar { @Indexed private String name; @StartNode private Person person; @EndNode private Car car; } @RelationshipEntity(type="OWNS") public class OwnsPet { @Indexed private String name; @EndNode private Person person; @StartNode private Pet pet; }
This saves the Graph database correctly without any problems, as I can query the actual Node and Relationship and see their type , etc.
But when I try to use @RelatedTo(type="OWNS", elementClass=Pet.class) , I either get a class exception, or when using lazy initialization I get incorrect results.
@NodeEntity public class Person { @Indexed private String name; @RelatedTo(type="OWNS", direction=Direction.OUTGOING, elementClass=Pet.class) private Set<Pet> pets; @RelatedTo(type="OWNS", direction=Direction.OUTGOING, elementClass=Car.class) private Set<Car> cars; }
The result that I get when I try to print my my man (my toString() was omitted, but it just calls toString() for each field):
Person [nodeId=1, name=Nick, pets=[Car [nodeId=3, name=Thunderbird]], cars=[Car [nodeId=3, name=Thunderbird]]]
Does anyone know if this can be done, it must be done, is it just a bug or a missing function?