![](/img/trans.png)
[英]Add a second label to an inherited node in spring-data-neo4j-4
[英]How do I add a second label to a node in Spring Data Neo4J 3.0.0 (Release)?
在Neo4J中,我有一個@NodeEntity Person
。
我希望能夠添加其他標簽,例如:USER
, :CUSTOMER
, :OWNER
, :AGENT
等。
似乎spring-data-neo4j:3.0.0-RELEASE
支持@Labels
注釋,但是在嘗試使用它時我得到NullPointerException
。
@NodeEntity
public class Person {
@GraphId
Long id
@Indexed(unique=true)
String email
@Labels // <- Seems this is unsupported.
private Collection<String>labels
public void addLabel(String label) {
this.labels.add(label) // <- NullPointer thrown here.
}
}
我認為這是因為它尚未得到支持。 如果確實如此,有人會給我一個如何通過更新它后面的存儲庫來實現相同結果的示例,添加一個手動的@Query
注釋來添加標簽嗎?
我不知道如何:
如果您重新構建域對象以支持繼承,SDN將基於繼承樹派生其他標簽。
如果您想要多個標簽,請擴展父類,您將擁有所需的標簽。
例如,如果
@NodeEntity
public class User extends Customer {
}
將生成兩個標簽:User和:Customer。
有關在 Neo4j上使用抽象類,請參閱在接口/抽象類上使用@NodeEntity 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.