How to add a second label to a node in Spring Data Neo4J 3.0.0 (Release)?

In Neo4J I have @NodeEntity Person

.

I would also like to add more labels, such as :USER

, :CUSTOMER

, :OWNER

, :AGENT

etc.

Seems to spring-data-neo4j:3.0.0-RELEASE

have annotation support @Labels

, but when I try to use it I get a 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.
    }
}

      

I assume this is because it is not supported yet. If this is indeed the case, then would anyone kindly provide me with an example of how to achieve the same result by updating the repository behind it, adding manual annotation @Query

to add the label?

I'm not sure how:

  • Reference to the current node in the request.
  • Execute cypher after calling save () method and creating node.
+3


source to share


1 answer


If you modify your domain objects to support inheritance, SDN will infer additional labels based on the inheritance tree.

if you want more than one label, extend the parent classes and you will have the label you want.

For example, if



@NodeEntity
public class User extends Customer {

}

      

Creates two labels: User and: Client.

See Use @NodeEntity in interface / abstract class when using abstract classes with Neo4j.

+2


source







All Articles