Reputation: 3056
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!
Upvotes: 3
Views: 2221
Reputation: 41706
Sorry to disappoint you, but during the retrieval the code right now doesn't look for the type class but rather for the type from @RelatedToVia
or @RelationshipEntity
or the field name relationships
as relationship-type. But you're making a valid point, can you please raise in issue in JIRA?
Did you look into template.getRelationshipsBetween
?
Why don't you create individual classes for your relationships? What is the use-case for this approach?
Upvotes: 2