-
Dec 25th, 2012, 08:10 AM
#1
can't query by relation entity
tl;dr: I get an exception: Index 0 not valid
Using spring-data neo4j, I have 2 node entities: snippet and person. Each snippet has an author. Following are the classes and then the test and failure:
@NodeEntity
public class SnippetLink {
@GraphId
@GeneratedValue
Long id;
@Fetch
@RelatedTo(type = "AUTHORED")
@Indexed
PersonLink author;
@RelatedToVia(type = SnippetRelation.DERIVED_FROM)
SnippetLink parent;
Long documentId;
public SnippetLink() {
}
public SnippetLink(PersonLink author, Long documentId) {
this.author = author;
this.documentId = documentId;
}
public PersonLink getAuthor() {
return author;
}
public void setAuthor(PersonLink author) {
this.author = author;
}
public Long getDocumentId() {
return documentId;
}
public void setDocumentId(Long documentId) {
this.documentId = documentId;
}
public SnippetLink getParent() {
return parent;
}
public void setParent(SnippetLink parent) {
this.parent = parent;
}
public SnippetRelation fork(PersonLink author) {
SnippetLink child = new SnippetLink(author, documentId);
return new SnippetRelation(this, child, SnippetRelation.Type.Fork);
}
public SnippetRelation revision(Long documentId) {
SnippetLink child = new SnippetLink(getAuthor(), documentId);
return new SnippetRelation(this, child, SnippetRelation.Type.Revision);
}
}
.
@NodeEntity
public class PersonLink {
@GraphId
Long id;
String login;
String firstName;
String lastName;
public PersonLink() {
}
public PersonLink(String login, String firstName, String lastName) {
this.login = login;
this.firstName = firstName;
this.lastName = lastName;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
.
public interface SnippetLinkRepository extends GraphRepository<SnippetLink>{
Iterable<SnippetLink> findByAuthor(PersonLink author);
}
.
The test:
PersonLink author = template.save(new PersonLink("johns", "John", "Smith"));
SnippetLink snippet = template.save(new SnippetLink(author, -1L));
SnippetRelation revisionRelation = snippet.revision(-2L);
template.save(revisionRelation.getChild());
template.save(revisionRelation);
Iterable<SnippetLink> snippets = snippetLinkRepository.findByAuthor(author);
assertThat(snippets).hasSize(2);
The exception:
org.springframework.dao.InvalidDataAccessApiUsageE xception: Index 0 not valid; nested exception is java.lang.IllegalArgumentException: Index 0 not valid
at org.springframework.data.neo4j.support.Neo4jExcept ionTranslator.translateExceptionIfPossible(Neo4jEx ceptionTranslator.java:43)
at org.springframework.dao.support.ChainedPersistence ExceptionTranslator.translateExceptionIfPossible(C hainedPersistenceExceptionTranslator.java:58)
at org.springframework.dao.support.DataAccessUtils.tr anslateIfNecessary(DataAccessUtils.java:213)
at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.invoke(PersistenceExcepti onTranslationInterceptor.java:163)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:204)
at $Proxy34.findByAuthor(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at org.springframework.aop.support.AopUtils.invokeJoi npointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:198)
at $Proxy36.findByAuthor(Unknown Source)
at com.tikalk.fuse.springdata.domain.neo4j.Neo4jTest. snippetsHaveAuthors(Neo4jTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at org.junit.runners.model.FrameworkMethod$1.runRefle ctiveCall(FrameworkMethod.java:45)
at org.junit.internal.runners.model.ReflectiveCallabl e.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExpl osively(FrameworkMethod.java:42)
at org.junit.internal.runners.statements.InvokeMethod .evaluate(InvokeMethod.java:20)
at org.springframework.test.context.junit4.statements .RunBeforeTestMethodCallbacks.evaluate(RunBeforeTe stMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements .RunAfterTestMethodCallbacks.evaluate(RunAfterTest MethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements .SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:231)
at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.runChild(SpringJUnit4ClassRunner.jav a:88)
at org.junit.runners.ParentRunner$3.run(ParentRunner. java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRu nner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentR unner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRu nner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRu nner.java:222)
at org.springframework.test.context.junit4.statements .RunBeforeTestClassCallbacks.evaluate(RunBeforeTes tClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements .RunAfterTestClassCallbacks.evaluate(RunAfterTestC lassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.ja va:300)
at org.springframework.test.context.junit4.SpringJUni t4ClassRunner.run(SpringJUnit4ClassRunner.java:174 )
at org.junit.runner.JUnitCore.run(JUnitCore.java:157)
at com.intellij.rt.execution.junit.JUnitStarter.main( JUnitStarter.java:63)
Caused by: java.lang.IllegalArgumentException: Index 0 not valid
at org.springframework.data.neo4j.repository.query.Cy pherQueryBuilder.getPartInfo(CypherQueryBuilder.ja va:105)
at org.springframework.data.neo4j.repository.query.De rivedCypherRepositoryQuery.resolveParameter(Derive dCypherRepositoryQuery.java:59)
at org.springframework.data.neo4j.repository.query.Gr aphQueryMethod.resolveParams(GraphQueryMethod.java :80)
at org.springframework.data.neo4j.repository.query.Gr aphRepositoryQuery.resolveParams(GraphRepositoryQu ery.java:74)
at org.springframework.data.neo4j.repository.query.Gr aphRepositoryQuery.execute(GraphRepositoryQuery.ja va:68)
at org.springframework.data.neo4j.repository.query.De rivedCypherRepositoryQuery.execute(DerivedCypherRe positoryQuery.java:34)
at org.springframework.data.repository.core.support.R epositoryFactorySupport$QueryExecutorMethodInterce ptor.invoke(RepositoryFactorySupport.java:302)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:110)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :172)
at org.springframework.dao.support.PersistenceExcepti onTranslationInterceptor.invoke(PersistenceExcepti onTranslationInterceptor.java:155)
... 37 more
-
Jan 7th, 2013, 02:54 AM
#2
What version of SDN are you using?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules