Announcement Announcement Module
No announcement yet.
Use of template.fetch() for a relationship entity? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

  • #2
    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:

    return type;


    return RelationshipTypes.XXX;