2
votes

I'm trying to upgrade to Neo4j 2.0, and Spring Data 3.0. I'm getting a null pointer when the application starts, before any of my code is executed.

Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (ref:ReferenceNode {name:{name}}) RETURN ref; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (ref:ReferenceNode {name:{name}}) RETURN ref; nested exception is java.lang.NullPointerException
at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:56)
at org.springframework.data.neo4j.support.ReferenceNodes.executeQuery(ReferenceNodes.java:77)
at org.springframework.data.neo4j.support.ReferenceNodes.getReferenceNode(ReferenceNodes.java:81)
at org.springframework.data.neo4j.support.typerepresentation.SubReferenceNodeTypeRepresentationStrategy.isStrategyAlreadyInUse(SubReferenceNodeTypeRepresentationStrategy.java:95)
at org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.chooseStrategy(TypeRepresentationStrategyFactory.java:56)
at org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.<init>(TypeRepresentationStrategyFactory.java:39)
at org.springframework.data.neo4j.config.Neo4jConfiguration.typeRepresentationStrategyFactory(Neo4jConfiguration.java:146)
at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$4b018b97.CGLIB$typeRepresentationStrategyFactory$6(<generated>)
at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$4b018b97$$FastClassByCGLIB$$5306fd26.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:286)
at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$4b018b97.typeRepresentationStrategyFactory(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:160)
... 112 more
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement MATCH (ref:ReferenceNode {name:{name}}) RETURN ref; nested exception is java.lang.NullPointerException
at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:67)
at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:53)
... 128 more
Caused by: java.lang.NullPointerException
at org.neo4j.cypher.ExecutionEngine.prepare(ExecutionEngine.scala:75)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:60)
at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:65)
at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:78)
at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:65)
... 129 more

Neo4j and spring-data dependencies on Pom.xml

<properties>
    <spring.version>3.2.6.RELEASE</spring.version>
    <springSecurity.version>3.2.0.RELEASE</springSecurity.version>
    <jackson.version>1.9.13</jackson.version>
    <neo4j.version>2.0.0</neo4j.version>
    <springDataNeo4j.version>3.0.0.RC1</springDataNeo4j.version>
    <neo4j-rest-graphdb.version>2.0.0</neo4j-rest-graphdb.version>
</properties>
<!--Neo4j-->
    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j</artifactId>
        <version>${neo4j.version}</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>${springDataNeo4j.version}</version>
    </dependency>


    <dependency>
        <groupId>org.neo4j</groupId>
        <artifactId>neo4j-rest-graphdb</artifactId>
        <version>${neo4j-rest-graphdb.version}</version>
    </dependency>

Context file

<neo4j:config graphDatabaseService="graphDatabaseService" />

<bean id="graphDatabaseService" class="org.neo4j.rest.graphdb.RestGraphDatabase">
    <constructor-arg value="http://localhost:7474/db/data"/>
</bean>

<context:annotation-config />

Neo4j is up and running.

When connecting through http://localhost:7474/browser/ everything works fine, including the offending query MATCH (ref:ReferenceNode {name:{name}}) RETURN ref;

1

1 Answers

1
votes

I believe that you don't need any org.neo4j.* dependencies. Maybe it would work with only <artifactId>spring-data-neo4j</artifactId> and <artifactId>spring-data-neo4j-rest</artifactId>. This is the configuration you should try :

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>3.0.0.RC1</version>
</dependency>
<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j-rest</artifactId>
    <version>3.0.0.RC1</version>
</dependency>

Update

What is sure is that the error message is generated by org.springframework.data.neo4j.support.ReferenceNodes in getReferenceNode (http://bit.ly/1eDYlYS).

The getReferenceNode method is called only from one place in SDN, at org.springframework.data.neo4j.support.typerepresentation.SubReferenceNodeTypeRepresentationStrategy (http://bit.ly/LW5gly).

This call is looking for a node with label :ReferenceNode and an attribute name equal to root.

So I would suggest trying to create such a node using Cypher :

CREATE (n:ReferenceNode {name:"root"}) RETURN n;

and see if the error still happens.