Spring Data Neo4J @Query throws NoSuchElementException when Cypher query has no result

225 views
Skip to first unread message

Steven Kalemkiewicz

unread,
Aug 29, 2012, 4:18:55 PM8/29/12
to ne...@googlegroups.com
Hello!

I'm running into a problem that seems exactly like bug DATAGRAPH-185 (Resolved in 2.1.M1) on spring-data-neo4j-2.1.0.BUILD-SNAPSHOT.

I have a graph structure where an Individual (node) is connected to 0 or more Events (node). Each Event is connected with a single Individual.

@NodeEntity
public class Individual
{
    @GraphId
    private Long id;

    // Date of earliest occurring event of type BIRTH.
    @Query(value = "start n=node({self}) match (n)-[:INDIVIDUAL_EVENT]->(event) where event.type = 'BIRTH' return event.date order by event.date desc limit 1")
    private Date birthDate;
}

@NodeEntity
public class IndividualEvent
{
    @GraphId
    private Long id;
   
    @Fetch
    @RelatedTo(type="INDIVIDUAL_EVENT", direction = Direction.INCOMING)
    private Individual individual;
   
    private IndividualEventType type; // Enum

    private Date date;
}


When I create a new Individual and save it using

Individual ind = new Individual();
            
IndividualEvent birth;
if (webform.getBirthDate() != null)
{
    birth = new IndividualEvent(IndividualEventType.BIRTH);
    birth.setDate(webform.getBirthDate());
    ind.addEvent(birth);
}
       
repos.save(ind);  // This is IndividualService.java line 58


I get the following exception and stack trace if I don't specify "birth" information (webform.getBirthDate() == null).

java.util.NoSuchElementException: No element found in IteratorWrapper(empty iterator)
	at org.neo4j.helpers.collection.IteratorUtil.assertNotNull(IteratorUtil.java:183)
	at org.neo4j.helpers.collection.IteratorUtil.single(IteratorUtil.java:136)
	at org.neo4j.helpers.collection.IteratorUtil.single(IteratorUtil.java:274)
	at org.springframework.data.neo4j.conversion.QueryResultBuilder$1.single(QueryResultBuilder.java:79)
	at org.springframework.data.neo4j.fieldaccess.QueryFieldAccessorFactory$QueryFieldAccessor.executeQuery(QueryFieldAccessorFactory.java:113)
	at org.springframework.data.neo4j.fieldaccess.QueryFieldAccessorFactory$QueryFieldAccessor.getValue(QueryFieldAccessorFactory.java:99)
	at org.springframework.data.neo4j.fieldaccess.DefaultEntityState.getValue(DefaultEntityState.java:97)
	at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyEntityStatePropertyValue(SourceStateTransmitter.java:110)
	at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.access$000(SourceStateTransmitter.java:39)
	at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$1.doWithPersistentProperty(SourceStateTransmitter.java:57)
	at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter$1.doWithPersistentProperty(SourceStateTransmitter.java:54)
	at org.springframework.data.mapping.model.BasicPersistentEntity.doWithProperties(BasicPersistentEntity.java:173)
	at org.springframework.data.neo4j.support.mapping.SourceStateTransmitter.copyPropertiesFrom(SourceStateTransmitter.java:54)
	at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.loadEntity(Neo4jEntityConverterImpl.java:98)
	at org.springframework.data.neo4j.support.mapping.Neo4jEntityConverterImpl.read(Neo4jEntityConverterImpl.java:90)
	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister$CachedConverter.read(Neo4jEntityPersister.java:168)
	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.createEntityFromState(Neo4jEntityPersister.java:186)
	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:239)
	at org.springframework.data.neo4j.support.mapping.Neo4jEntityPersister.persist(Neo4jEntityPersister.java:227)
	at org.springframework.data.neo4j.support.Neo4jTemplate.save(Neo4jTemplate.java:295)
	at org.springframework.data.neo4j.repository.AbstractGraphRepository.save(AbstractGraphRepository.java:106)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.executeMethodOn(RepositoryFactorySupport.java:323)
	at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:308)
	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 $Proxy26.save(Unknown Source)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at java.lang.reflect.Method.invoke(Method.java:597)
	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
	at $Proxy28.save(Unknown Source)
	at dixon.service.IndividualService.createNewUnconnectedIndividual(IndividualService.java:58)
// Spring MVC calls before this point.

I don't get the exception and the application works as expected if I specify "birth" information (webform.getBirthDate()!= null)

Any ideas?

Thanks in advance.

Steven Kalemkiewicz

unread,
Aug 29, 2012, 4:23:33 PM8/29/12
to ne...@googlegroups.com
Also wanted to add a few other bits of version information:

Platform: Windows 7
JDK: 1.6.0_34
spring.version: 3.1.0.RELEASE
spring-data-neo4j.version: 2.1.0.BUILD-SNAPSHOT
neo4j.version: 1.8.M06

Lasse Westh-Nielsen

unread,
Aug 30, 2012, 4:53:36 AM8/30/12
to ne...@googlegroups.com
Steven,

I have been unable to reproduce this.

Could you possibly share a small test (preferably maven-based) project on github, with a test that illustrates the problem? Then I would be happy to take a look again.

Regards,

Lasse





--
 
 

Steven Kalemkiewicz

unread,
Aug 31, 2012, 2:12:16 PM8/31/12
to ne...@googlegroups.com
I've been having an email discussion with Lasse Westh-Nielsen about this issue since his response on 30 August.

I posted a copy of my source to github and the code worked as expected. He suggested that I wipe out my local copy, check out from scratch, wipe the database, wipe the webapps directory, running mvn -U to get updates, etc. This is pretty much what I ended up doing.

Seems like there was an old Spring/Neo4J JAR being left between compiles when I was using Eclipse.

Everything is working as expected now!

-Steve

Reply all
Reply to author
Forward
0 new messages