@RelationshipType
当关系类型用字段注释时,我在检索关系时遇到困难。
Neoclipse 中的关系看起来是正确的,但我在我的应用程序中没有检索到任何结果。
不起作用的代码是(简化的):
@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;
}
...
}
和:
@RelationshipEntity
public class Relationship {
@RelationshipType
private String type;
...
}
有效的代码是:
@RelationshipEntity(type = "something")
public class Relationship {
...
}
但是,这不适合我的用例(我在任意实例Relationship
组合之间有一堆不同的类型。Entity
完整的测试代码如下。Agency
并且Item
都是 的子类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));
最后一行是测试失败的地方。有什么线索吗?
米
PS。我是 Neo4j 的业余爱好者,碰巧发现了@RelationshipType
,所以我很可能做错了可笑的事情。但愿如此!