[Neo4j] [SDN] Example of using Gremlin with Spring-Data repository?

274 views
Skip to first unread message

Marc de Verdelhan

unread,
Mar 12, 2012, 1:12:07 PM3/12/12
to ne...@googlegroups.com
Hello,

Does anyone would have a detailed example of using Gremlin (All what I found was using Cypher) with SDN repositories?

I get an exception when I try to call this method:

public interface MyRepository extends GraphRepository<Project> {
@Query(value="{0}", type=QueryType.Gremlin)
String findOtherProjectsOfOwner(Project myProject);
}

The exception:

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 6.278 sec <<< FAILURE!
testFindOtherProjectsOfOwner(com.mygroup.myapp.data.MyRepositoryTest)  Time elapsed: 5.78 sec  <<< ERROR!
org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement {0}; nested exception is java.lang.NullPointerException
at org.springframework.data.neo4j.support.query.GremlinQueryEngine.query(GremlinQueryEngine.java:50)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:96)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:70)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
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 $Proxy39.findProductCycles(Unknown Source)
at com.mygroup.myapp.data.MyRepositoryTest.testFindOtherProjectsOfOwner(MyRepositoryTest.java:61)

Regards,

MV

Peter Neubauer

unread,
Mar 12, 2012, 1:53:14 PM3/12/12
to ne...@googlegroups.com
Here is a test doing that, is that what you are looking for?
https://github.com/SpringSource/spring-data-neo4j/blob/master/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/PersonRepository.java#L43

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

Marc de Verdelhan

unread,
Mar 13, 2012, 7:50:44 AM3/13/12
to ne...@googlegroups.com
Thank you for your answer Peter. It's what I was looking for. :)

The exception was occuring because I had forgotten to add gremlin-groovy to my pom.xml

Cheers,

MV

Marc de Verdelhan

unread,
Mar 13, 2012, 8:30:07 AM3/13/12
to ne...@googlegroups.com
Is the Gremlin query engine fully compatible with the original Gremlin?
This statement works fine: @Query(value="g.v(project)", type=QueryType.Gremlin)
... but this one ( @Query(value="g.v(project).as('p')", type=QueryType.Gremlin) ) throws an exception:

java.lang.NoClassDefFoundError: com/tinkerpop/pipes/util/Table
at org.springframework.data.neo4j.support.query.GremlinExecutor.getRepresentation(GremlinExecutor.java:90)
at org.springframework.data.neo4j.support.query.GremlinExecutor.query(GremlinExecutor.java:62)
at org.springframework.data.neo4j.support.query.GremlinQueryEngine.query(GremlinQueryEngine.java:47)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:96)
at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:70)
at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:302)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
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 $Proxy39.findOtherProjectsOfOwner(Unknown Source)
at com.mygroup.myapp.data.MyRepositoryTest.testFindOtherProjectsOfOwner(MyRepositoryTest.java:55)
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:616)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
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:82)
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:50)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
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: com.tinkerpop.pipes.util.Table
at java.net.URLClassLoader$1.run(URLClassLoader.java:217)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:205)
at java.lang.ClassLoader.loadClass(ClassLoader.java:321)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294)
at java.lang.ClassLoader.loadClass(ClassLoader.java:266)
... 42 more

Cheers,

MV

Peter Neubauer

unread,
Mar 13, 2012, 8:39:50 AM3/13/12
to ne...@googlegroups.com
Marc,
this sounds like a version clash. What version of Gremlin and Neo4j
Server are you running? The latest SNAPSHOTS have been updated to
Gremlin 1.5 which has a different package fo the Table class

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

On Tue, Mar 13, 2012 at 1:30 PM, Marc de Verdelhan

Marc de Verdelhan

unread,
Mar 13, 2012, 9:14:22 AM3/13/12
to ne...@googlegroups.com
I pasted my pom.xml here: http://paste.pocoo.org/show/565047/
I tried to upgrade to Neo4j 1.7-SNAPSHOT but then I get "Failed to load ApplicationContext" errors on my unit tests. :/

MV

Peter Neubauer

unread,
Mar 13, 2012, 9:34:04 AM3/13/12
to ne...@googlegroups.com
Ahh,
you are runnign on Neo4j 1.6.1 but with Gremlin 1.5. You need to
downgrade to Gremlin 1.4. Try that and report back.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

On Tue, Mar 13, 2012 at 2:14 PM, Marc de Verdelhan

Marc de Verdelhan

unread,
Mar 13, 2012, 10:25:56 AM3/13/12
to ne...@googlegroups.com
Oh! Ok, works fine now (with Gremlin 1.4).
But what if I want to upgrade to 1.5? I understood that I would need Neo4j 1.7 but it returns me "Failed to load ApplicationContext" erros. I don't see the connection with the ApplicationContext. O_o

Thank you. :)

MV

Peter Neubauer

unread,
Mar 13, 2012, 6:42:10 PM3/13/12
to ne...@googlegroups.com
Marc,
no idea what that is but I guess mixing versions is not good. 1.7.M01
is out soon, and the SDN can be updated also.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

On Tue, Mar 13, 2012 at 3:25 PM, Marc de Verdelhan

Marc de Verdelhan

unread,
Mar 14, 2012, 10:22:07 AM3/14/12
to ne...@googlegroups.com
OK. I'll wait for a SDN update. Do you know when Neo4j 1.7 will be released?

Cheers,

MV

Peter Neubauer

unread,
Mar 16, 2012, 8:38:33 AM3/16/12
to ne...@googlegroups.com
It is now :) http://blog.neo4j.org/2012/03/neo4j-17m01-bank.html

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

Neo4j 1.6 released                 - dzone.com/6S4K
The Neo4j Heroku Challenge   - http://neo4j-challenge.herokuapp.com/

On Wed, Mar 14, 2012 at 3:22 PM, Marc de Verdelhan

Marc de Verdelhan

unread,
Mar 16, 2012, 9:16:45 AM3/16/12
to ne...@googlegroups.com
\o/
Thank you Peter.

Waiting for a SDN update now.

Cheers,

MV
Reply all
Reply to author
Forward
0 new messages