Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring Data Neo4j Sample program error
    primarykey
    data
    text
    <p>I am creating a small application for getting to know Neo4j and Spring Data Neo4j. But I got NullPointerException always. Hence I used one of the most <a href="https://github.com/SpringSource/spring-data-neo4j/tree/master/spring-data-neo4j-examples/hello-worlds" rel="nofollow">simple examples</a> of Spring Data Neo4j and have updated the test file with main() from JUnit. My Test File is as follows:</p> <pre><code>package com.spring.nosql.neo4j.worldTest; import java.util.Collection; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.graph.neo4j.template.Neo4jTemplate; import org.springframework.test.annotation.Rollback; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.transaction.annotation.Transactional; /** * @author srahul07 * */ @ContextConfiguration(locations = "classpath:neo4jBeans.xml") @Transactional public class Main { @Autowired private GalaxyService galaxyService; @Autowired private Neo4jTemplate template; @Rollback(false) @BeforeTransaction public void shouldAllowDirectWorldCreation() { // assertEquals(0, galaxyService.getNumberOfWorlds()); System.out.println("Number of Worlds: " + galaxyService.getNumberOfWorlds()); World myWorld = galaxyService.createWorld("mine", 0); System.out.println("Number of Worlds: " + galaxyService.getNumberOfWorlds()); // assertEquals(1, galaxyService.getNumberOfWorlds()); Iterable&lt;World&gt; foundWorlds = galaxyService.getAllWorlds(); World mine = foundWorlds.iterator().next(); System.out.println("Number of Worlds: " + myWorld.getName() + " Name: " + mine.getName()); // assertEquals(myWorld.getName(), mine.getName()); } public void shouldHaveCorrectNumberOfWorlds() { galaxyService.makeSomeWorlds(); System.out.println("Number of Worlds: " + galaxyService.getNumberOfWorlds()); // assertEquals(13, galaxyService.getNumberOfWorlds()); } public void shouldFindWorldsById() { galaxyService.makeSomeWorlds(); for (World world : galaxyService.getAllWorlds()) { World foundWorld = galaxyService.findWorldById(world.getId()); System.out.println("Found World: " + foundWorld); // assertNotNull(foundWorld); } } public void shouldFindWorldsByName() { galaxyService.makeSomeWorlds(); for (World world : galaxyService.getAllWorlds()) { World foundWorld = galaxyService.findWorldByName(world.getName()); System.out.println("Found Worlds: " + foundWorld); // assertNotNull(foundWorld); } } public void shouldReachMarsFromEarth() { galaxyService.makeSomeWorlds(); World earth = galaxyService.findWorldByName("Earth"); World mars = galaxyService.findWorldByName("Mars"); System.out.println("Mars Rechable from Earth: " + mars.canBeReachedFrom(earth)); System.out.println("Earth Reachable from Mars: " + earth.canBeReachedFrom(mars)); // assertTrue(mars.canBeReachedFrom(earth)); // assertTrue(earth.canBeReachedFrom(mars)); } public void shouldFindAllWorlds() { Collection&lt;World&gt; madeWorlds = galaxyService.makeSomeWorlds(); Iterable&lt;World&gt; foundWorlds = galaxyService.getAllWorlds(); int countOfFoundWorlds = 0; for (World foundWorld : foundWorlds) { System.out.println("Worlds Contains: " + madeWorlds.contains(foundWorld)); // assertTrue(madeWorlds.contains(foundWorld)); countOfFoundWorlds++; } System.out.println("World's Size: " + madeWorlds.size() + " Count of Found Worlds: " + countOfFoundWorlds); // assertEquals(madeWorlds.size(), countOfFoundWorlds); } @SuppressWarnings("unchecked") public void shouldFindWorldsWith1Moon() { galaxyService.makeSomeWorlds(); for (World worldWithOneMoon : galaxyService.findAllByNumberOfMoons(1)) { System.out.println("World With One Moon: " + worldWithOneMoon.getName()); System.out.println("World With One Moon is Earth?: " + worldWithOneMoon.getName().contains("Earth")); System.out.println("World With One Moon is Earth?: " + worldWithOneMoon.getName().contains("Midgard")); /* * assertThat( worldWithOneMoon.getName(), * is(anyOf(containsString("Earth"), containsString("Midgard")))); */ } } public void shouldNotFindKrypton() { galaxyService.makeSomeWorlds(); World krypton = galaxyService.findWorldByName("Krypton"); System.out.println("World is Krypton: " + krypton.getName().isEmpty()); // assertNull(krypton); } /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub try { Main mainTest = new Main(); mainTest.shouldHaveCorrectNumberOfWorlds(); mainTest.shouldAllowDirectWorldCreation(); mainTest.shouldFindAllWorlds(); mainTest.shouldFindWorldsById(); mainTest.shouldFindWorldsByName(); mainTest.shouldFindWorldsWith1Moon(); mainTest.shouldNotFindKrypton(); mainTest.shouldReachMarsFromEarth(); } catch (Exception ae) { ae.printStackTrace(); } } } </code></pre> <p>My Spring context configurations is as follows:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt; &lt;context:spring-configured/&gt; &lt;context:annotation-config/&gt; &lt;context:component-scan base-package="com.spring.nosql.neo4j.worldTest" /&gt; &lt;neo4j:config storeDirectory="target/neo4j-db"/&gt; &lt;neo4j:repositories base-package="com.spring.nosql.neo4j.worldTest"/&gt; &lt;/beans&gt; </code></pre> <p>Whenever I run my test code, I get following Error:</p> <pre><code>java.lang.NullPointerException at com.spring.nosql.neo4j.worldTest.Main.shouldHaveCorrectNumberOfWorlds(Main.java:48) at com.spring.nosql.neo4j.worldTest.Main.main(Main.java:141) </code></pre> <p>Is there anything I missed in my configurations? Or is there anything extra needed here? As far as I understood, the Neo4j will create graph database in "target/neo4j-db". Also, since my machine is Ubuntu I have installed debian package of Neo4j on my machine. So I also tried to use it via using REST API. So for this I made following configurations to my spring context file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:neo4j="http://www.springframework.org/schema/data/neo4j" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/data/neo4j http://www.springframework.org/schema/data/neo4j/spring-neo4j.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt; &lt;context:spring-configured/&gt; &lt;context:annotation-config/&gt; &lt;context:component-scan base-package="com.spring.nosql.neo4j.worldTest" /&gt; &lt;neo4j:repositories base-package="com.spring.nosql.neo4j.worldTest"/&gt; &lt;neo4j:config graphDatabaseService="graphDatabaseService"/&gt; &lt;bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase"&gt; &lt;constructor-arg index="0" value="http://localhost:7474/db/data" /&gt; &lt;constructor-arg index="1" value="" /&gt; &lt;constructor-arg index="2" value="" /&gt; &lt;/bean&gt; </code></pre> <p>But still I am getting same Exception.</p> <p>FYI: I have included Spring, Spring Data Neo4j and Neo4j libraries to my buildpath in Eclipse.</p> <p>EDIT:</p> <p>Well since there was no response on this, I tried the same example as it is with JUnit Test case as per provided in examples <a href="https://github.com/SpringSource/spring-data-neo4j/tree/master/spring-data-neo4j-examples/hello-worlds" rel="nofollow">here</a>:</p> <p>In my JUnit test case I got following errors on each of the methods:</p> <pre><code>java.lang.NoClassDefFoundError: org/neo4j/cypherdsl/grammar/Execute at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2442) at java.lang.Class.getDeclaredMethods(Class.java:1808) at org.springframework.util.ReflectionUtils.findMethod(ReflectionUtils.java:154) at org.springframework.util.ClassUtils.getMostSpecificMethod(ClassUtils.java:730) at org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$AbstractFallbackTransactionAttributeSource.computeTransactionAttribute(TransactionalRepositoryProxyPostProcessor.java:326) at org.springframework.data.repository.core.support.TransactionalRepositoryProxyPostProcessor$AbstractFallbackTransactionAttributeSource.getTransactionAttribute(TransactionalRepositoryProxyPostProcessor.java:282) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:99) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:155) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202) at $Proxy31.count(Unknown Source) at com.spring.nosql.neo4j.worldTest.GalaxyService.getNumberOfWorlds(GalaxyService.java:16) at com.spring.nosql.neo4j.worldTest.GalaxyServiceTest.shouldAllowDirectWorldCreation(GalaxyServiceTest.java:40) 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:601) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20) at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74) at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83) at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222) at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61) at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71) at org.junit.runners.ParentRunner.run(ParentRunner.java:300) at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.ClassNotFoundException: org.neo4j.cypherdsl.grammar.Execute at java.net.URLClassLoader$1.run(URLClassLoader.java:366) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:423) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:356) ... 43 more </code></pre> <p>This says that the class named: org/neo4j/cypherdsl/grammar/Execute is not found or missing.</p> <p>This does mean that I am missing one of the library, but the Neo4j Library shows the package named <code>neo4j-cypher-1.8.jar</code>. But in this I have not found <code>cypherdsl</code>.</p> <p>Edit2:</p> <p>Well finally it worked with JUnit but not with the <code>public static void main()</code> <code>[psvm]</code>. I was missing one library called <code>cypherdsl</code> which can be downloaded from <a href="http://m2.neo4j.org/content/repositories/releases/org/neo4j/neo4j-cypher-dsl/1.8/neo4j-cypher-dsl-1.8.jar" rel="nofollow">here</a>. But why it does not work when I go for <code>psvm</code>?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload