3

In Neo4J I have a @NodeEntity Person.

I'd like to be able to also add additional labels such as :USER, :CUSTOMER, :OWNER, :AGENT, etc.

It seems that spring-data-neo4j:3.0.0-RELEASE has support for an @Labels annotation, but I get a NullPointerException when trying to use it.

@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's not yet supported. If this is indeed the case, would someone kindly give me an example of how to achieve the same result by updating the repository behind it, adding a manual @Query annotation to add the label?

I'm not sure how to:

  1. Reference the current node in the query.
  2. Execute the cypher after the save() method has been called and the node has been created.
sparkyspider
  • 13,195
  • 10
  • 89
  • 133
  • There is an issue still unresolved about this. [See](https://jira.spring.io/browse/DATAGRAPH-541) – troig May 13 '15 at 18:50

1 Answers1

2

If you remodel your domain objects to support inheritance, SDN will derive additional labels based on inheritance tree.

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

For example, if

@NodeEntity
public class User extends Customer {

}

Will generate two labels :User and :Customer.

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

Community
  • 1
  • 1
F.O.O
  • 4,730
  • 4
  • 24
  • 34