Spring Data Neo4j-@RelationshipType问题 [英] Spring Data Neo4j - @RelationshipType issues
问题描述
当使用@RelationshipType
字段注释关系类型时,检索关系很困难.
I'm having difficulties retrieving relationships when the relationship type is annotated with a @RelationshipType
field.
在Neoclipse中,这些关系看起来是正确的,但我的应用程序未检索到任何结果.
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;
}
...
}
和:
@RelationshipEntity
public class Relationship {
@RelationshipType
private String type;
...
}
起作用的代码是:
@RelationshipEntity(type = "something")
public class Relationship {
...
}
但是,这不适合我的用例(在Entity
实例的任意组合之间我有一堆不同的Relationship
类型.
However, this doesn't suit my use case (I have a bunch of different Relationship
types between arbitrary combinations of Entity
instances.
完整的测试代码如下. Agency
和Item
都是Entity
的子类.
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.我是Neo4j的业余爱好者,只是偶然发现了@RelationshipType
,所以我很可能在做可笑的错误.我希望是这样!
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!
推荐答案
很抱歉让您失望,但是在检索过程中,代码现在不查找类型类,而是查找@RelatedToVia
或relationships
作为关系类型.但是,您的观点是正确的,能否请您在 JIRA 中提出问题?
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?
您是否研究过template.getRelationshipsBetween
?
为什么不为您的关系创建单独的类?这种方法的用例是什么?
Why don't you create individual classes for your relationships? What is the use-case for this approach?
这篇关于Spring Data Neo4j-@RelationshipType问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!