1
votes

Trying to execute following method on UserRepository extends GraphRepository<User> but it is throwing an exception

@Query(
    "MERGE (user:User {appId:{0}, uid:{1}})" +
    "RETURN user"
)
public User createUserIfNotExists(String appId, String userId);

Exception:

java.lang.IllegalStateException: No primary SDN label exists .. (i.e one with starting with _) 
at org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypeRepresentationStrategy.readAliasFrom(LabelBasedNodeTypeRepresentationStrategy.java:125)
at org.springframework.data.neo4j.support.typerepresentation.LabelBasedNodeTypeRepresentationStrategy.readAliasFrom(LabelBasedNodeTypeRepresentationStrategy.java:42)

But changing the query to "MERGE (user:_User works and applies the label _User to the created node.

Q1. Can I tell SDN to attach only User as the label and avoid _User
Q2. If not, then how can I have both User and _User labels attached to all user nodes. At present only _User label is attached


Edited:

Issue1:

With my previous SDN version (i.e. 3.0.0.RELEASE), suddenly query user:User:_User started working but then failing for Song repository for the similar query song:Song:_Song but works for song:_Song or song:Song

Issue2:

The moment I update my SDN or Neo4j version, I get strange exceptions and that's why I didn't update my versions of SDN and Neo4j.

Just now I updated my SDN to version 3.1.1 and kept the neo4j version same (i.e. 2.0.1) and the code is also the same but then I got the following exception

Exception in thread "main" java.lang.IllegalArgumentException: Environment must not be null!
at org.springframework.util.Assert.notNull(Assert.java:112)
at org.springframework.data.repository.config.RepositoryConfigurationSourceSupport.<init>(RepositoryConfigurationSourceSupport.java:50)
at org.springframework.data.repository.config.AnnotationRepositoryConfigurationSource.<init>(AnnotationRepositoryConfigurationSource.java:74)
at org.springframework.data.repository.config.RepositoryBeanDefinitionRegistrarSupport.registerBeanDefinitions(RepositoryBeanDefinitionRegistrarSupport.java:74)
at org.springframework.context.annotation.ConfigurationClassParser.processImport(ConfigurationClassParser.java:396)
at org.springframework.context.annotation.ConfigurationClassParser.doProcessConfigurationClass(ConfigurationClassParser.java:207)

at line ApplicationContext appCtx = new AnnotationConfigApplicationContext(ApplicationConfig.class);

1

1 Answers

3
votes

It needs the labels with the underscore to identify the one which actually belongs to this class (in the inheritance hierarchy).

Michael

Use:

MERGE (user:User:_User {appId:{0}, uid:{1}})
RETURN user

or

MERGE (user:User {appId:{0}, uid:{1}})
ON CREATE SET user:_User
RETURN user