Why does Spring Data Neo4j create an underscore prefixed label on nodes?

匆匆过客 提交于 2019-12-11 02:18:46

问题


I realize that a similar question was asked here, but I'm trying to understand the reasoning behind the approach of SDN to create a label matching my class name, and also creating the same label prefixed by an underscore.

So, for example, I have a Patient class. When I create my @NodeEntity decorated Patient class through my Neo4j repository and then query it back through the Neo4j web console, I see Patient and _Patient as the labels.

As an extension to this question, say I have the following inheritance hierarchy of classes representing nodes:

@NodeEntity
public class Patient extends Person {
   //class definition here
}

@NodeEntity
public abstract class Person {
    //class definition here
}

When I save an instance of Patient to the database, it will have three labels: Person, Patient, _Patient. Why wouldn't my node also have an _Patient label?


回答1:


When your hierarchy has more than 1 (not abstract) classes the label prefixed with _ allows SDN to determine the type properly.

E.g. when you similar hierarchy

Person
Patient extends Person
EbolaPatient extends Patient

then let's say you save instance of class Patient then the node will have _Patient label, when you save EbolaPatient instance it will have _EbolaPatient label.

If you then retrieve the nodes (e.g. as a collection using findAll on a person repository) SDN will correctly instantiate the entities as Patient and EbolaPatient.

Other option how to implement this would be to find a label that is most down the class hierarchy, which is a lot more complicated than having additional prefixed label.

To see details how this is implemented see LabelBasedNodeTypeRepresentationStrategy class in SDN project.



来源:https://stackoverflow.com/questions/28728674/why-does-spring-data-neo4j-create-an-underscore-prefixed-label-on-nodes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!