Jun 13th, 2012, 08:37 AM
Use of template.fetch() for a relationship entity?
The javadoc for template.fetch() seems to imply that it can be used for relationship entities as well as node entities, but when I try to use it for a relationship entity I get a ClassCastException:
org.neo4j.kernel.impl.core.RelationshipProxy cannot be cast to org.neo4j.graphdb.Node
Is fetch() supposed to work for relationship entities or is it just for node entities?
If just for node entities, is there a recommended way to force the loading of properties for a relationship entity? When I use template.findOne(relationshipId, relationshipClass), the properties of the returned relationship entity object are null, presumably because it is lazy loaded.
Thanks for any help.
Jun 13th, 2012, 11:38 AM
Digging deeper, it seems I do not need fetch() for the relationship entity, as most of the properties are being populated, with the exception of the relationship type field (the field annotated with @RelationshipType). This field is null in the proxy object even though I initialize it in my entity class using:
RelationshipTypes type = RelationshipTypes.XXX;
I'm not sure whether this behavior is expected, but in any case I can work around this by simply changing the code in my getType() method from: