jasonfungsing
jasonfungsing

Reputation: 1655

SDN 4.0 multi labels for one @NodeEntity

I have my existing @NodeEntity as below

@NodeEntity
public class Company {

@GraphId
private Long id;

private String name;

private String blah;

and the @Repository

@Repository
public interface CompanyRepository extends GraphRepository<Company> {

Company findByName(String name);

To create a new Company in neo4j, simply do

Company company = new Company();
company.setName("Company Name");
repository.save(company);

This will create a Company node in neo4j with Label Company.

However, I also want to be able create this with a different label. Instead of creating a new @NodeEntity and a new @Repository, can I use existing domain and repo with a separate label to do it?

I had google this, most answers are only applied to SDN 3.*. Some of those suggest to have a collection field annotate with @Labels, but looks like this @Labels has been removed from SDN4.0

Upvotes: 1

Views: 520

Answers (2)

Luanne
Luanne

Reputation: 19373

As @MicTech pointed out, the only way of achieving this right now is via your object model.

But if you want to attach multiple labels to an existing node entity and repository, it's not possible in the current release. You could possibly have a server extension to assign additional labels but those would not really be usable by your repositories.

Unfortunately, we don't have a firm date for implementing this that we can commit to right now because the product road map is still being discussed.

Upvotes: 2

MicTech
MicTech

Reputation: 45123

This is a responsibility of Neo4j-OGM.

For multiple labels for the Node you should use inheritance in Java.

@NodeEntity
public abstract class DomainEntity { ... }

public class Company extends DomainObject { ... }

public class PublicCompany extends Company { ... }

Upvotes: 2

Related Questions