It's been more than a year since I posted this question. Reading it again, the problem is obvious to me now : I was completely misunderstanding and misusing the elementClass
attribute. When I wrote:
@RelatedTo(elementClass = CarNode.class, type = "drives", direction = OUTGOING)
private Set<Driver> drivers;
this is wrong, wrong, wrong.
The solution to my original question is to use the interface inside the field declaration (private Set<Driver> drivers;
), and the concrete implementation of the interface in the "elementClass" attribute of @RelatedTo
.
This is how it works now in my project:
@RelatedTo(elementClass = DriverNode.class, type = "drives", direction = OUTGOING)
private Set<Driver> drivers = new HashSet<Driver>(0);
So, the only place where you have to use the DriverNode
concrete class is inside elementClass
attribute. You don't need to use generics at all.
Foot-note : I don't use @Fetch
anymore.