I'm having difficulties retrieving relationships when the relationship type is annotated with a @RelationshipType
field.
The relationships look correct in Neoclipse, but I'm retrieving no results in my application.
The code that doesn't work is (simplified):
@NodeEntity
public abstract class Entity {
@RelatedToVia
private Collection<Relationship> relationships;
public Relationship relatedTo(Entity entity, String type) {
Relationship relationship = new Relationship(type, this, entity);
relationships.add(relationship);
return relationship;
}
...
}
and:
@RelationshipEntity
public class Relationship {
@RelationshipType
private String type;
...
}
The code that does work is:
@RelationshipEntity(type = "something")
public class Relationship {
...
}
However, this doesn't suit my use case (I have a bunch of different Relationship
types between arbitrary combinations of Entity
instances.
The full test code is below. Agency
and Item
are both subclasses of Entity
.
// Create first entity
Agency arnz = agencyRepository.save(new Agency());
arnz.setCode("ARNZ");
agencyRepository.save(arnz);
// Create second entity
Item r123 = itemRepository.save(new Item());
r123.setCode("R123");
// Create parent/child relationship between entities
r123.relatedTo(arnz, EntityRelationshipType.PARENT);
itemRepository.save(r123);
// Retrieve entity from database
Entity entity = itemRepository.findByCode("R123");
// Verify that relationship is present
assertThat(entity.getRelationships().iterator().hasNext(), is(true));
The final line is where the test is failing. Any clues?
M
PS. I'm a rank amateur with Neo4j and just happened to find @RelationshipType
, so I may well be doing something laughably wrong. I hope so!
itemRepository.getRelationshipBetween(r123, arnz, Relationship.class, EntityRelationshipType.PARENT);
returns the relationship as expected. However again, this isn't what my use case demands so isn't of much use! – nullPainterNode node = template.getNode(entity.getId());
and an subsequent call tonode.getRelationships();
also correctly returns the relationship, just in a less-useful node4j rawRelationship
type. So, clearly a Spring Data implementation issue rather than something fundamentally wrong in my graph? – nullPainter@RelatedToVia(direction = Direction.BOTH, type = EntityRelationshipType.PARENT)
(i.e., adding atype
). Which again isn't very useful as I require a heterogeneous set of relationship types in the same collection. Or is this just a restriction of the framework? I'm using 2.1.0.BUILD-SNAPSHOT. – nullPainter