【发布时间】:2014-01-16 14:26:35
【问题描述】:
我得到了一个由以下 Cypher 表达式描述的图表:
CREATE
(BMW:Brand {name: "BMW", country: "Germany"}),
(X3:Model {name: "X3", acceleration: 7.1, maxSpeed: 227.5, displacement: 1997, consumption: 6}),
(lastGen:Generation {from: 2013}),
(xDrive20i:Modification {name: "xDrive20i", maxSpeed: 210, acceleration: 8.3, consumption: 7.9}),
(X3)-[:MODEL_OF]->(BMW),
(BMW)-[:MODEL]->(X3),
(lastGen)-[:GENERATION_OF]->(X3),
(X3)-[:GENERATION]->(lastGen),
(xDrive20i)-[:MODIFICATION_OF]->(X3),
(X3)-[:MODIFICATION]->(xDrive20i),
(lastGen)-[:MODIFICATION]->(xDrive20i),
(xDrive20i)-[:MODIFICATION_OF]->(lastGen);
我描述了一个匹配Brand的数据结构的java类:
@NodeEntity
@TypeAlias("Brand")
public class Brand {
@GraphId
private Long id;
@Indexed(indexType = IndexType.FULLTEXT, indexName = "brand_name")
private String name;
private String origin;
private String owner;
@RelatedTo(type = "MODEL", direction = Direction.OUTGOING)
private Set<Model> models;
//getters and setters are ommited
}
和存储库:
public interface BrandRepository extends GraphRepository<Brand>{
//method's signatures are ommited
}
当我调用brandRepository.count() 时,它会按我的预期返回 1。但是如果我打电话给brandRepository.getOne(2249L) 我会得到一个例外:
java.lang.IllegalStateException: No primary SDN label exists .. (i.e one with starting with __TYPE__)
据我了解阅读LabelBasedNodeTypeRepresentationStrategy 源,节点必须至少有一个带有__TYPE__ 前缀的标签。
鉴于我可能无法更改图形结构,我如何将实体映射到图形?
如果没有其他方法,我不介意实现我自己的自定义 LabelBasedNodeTypeRepresentationStrategy。但在这种情况下,有人可以让我知道为什么它是这样实现的(我认为这不是偶然的)以及我应该如何将自定义解决方案绑定到 spring-data-neo4j 使用它?
我使用 neo4j-2.0.0-M06 和 spring-data-neo4j-3.0.0.M1。
【问题讨论】:
-
我没有找到问题的答案,但我以另一种方式解决了我的问题。我改用 Ruby 技术并使用了neo4j gem。它的行为完全符合我的预期,至少不会向我的数据添加元信息。
标签: java spring neo4j spring-data-neo4j