2013-05-02 2 views
0

Je reçois une exception étrange lorsque j'essaie d'exécuter une requête de chiffrement simple. Je vais d'abord présenter mon code, puis je montrerai ce qui cause l'exception. Donc, j'ai les classes suivantes:Spring Data Neo4j - Obtention d'une exception lors de l'exécution d'une requête chiffrée

Une classe simple pour représenter un profil d'utilisateur:

public abstract class Profile extends AbstractEntity { 

    @Indexed 
    ProfileType profileType; 

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "name") 
    String firstName; 

    @Indexed(indexType = IndexType.FULLTEXT, indexName = "name") 
    String lastName; 

    @Indexed 
    EyeColor eyeColor; 

    @Indexed  
    HairColor hairColor; 

    @Indexed 
    Nationality nationality; 

    @Indexed 
    int height; 

    public Profile() { 
     setProfileType(); 
    } 

    public Profile(String firstName, String lastName, Nationality nationality, EyeColor eyeColor, HairColor hairColor, int height) { 
     this(); 
     this.setFirstName(firstName); 
     this.setLastName(lastName); 
     this.setNationality(nationality); 
     this.setHairColor(hairColor); 
     this.setEyeColor(eyeColor); 
     this.setHeight(height); 
    } 

    /* Getters and Setters */ 
} 

Et une simple classe qui hérite de Profile, et représente un civil:

@NodeEntity 
public class Civilian extends Profile { 

    @GraphProperty(propertyType = Long.class) 
    DateTime dateOfBirth; 

    @Indexed 
    boolean missing; 

    @RelatedTo 
    @Fetch 
    Set<Casualty> casualties = new HashSet<Casualty>(); //TODO: design 

    public Civilian() { 
     this.profileType = ProfileType.CIVILIAN; 
    } 

    public Civilian(String firstName, String lastName, Nationality nationality, EyeColor eyeColor, HairColor hairColor, int height, DateTime dateOfBirth, boolean missing) { 
     super(firstName, lastName, nationality, eyeColor, hairColor, height); 
     this.setDateOfBirth(dateOfBirth); 
     this.setMissing(missing); 
    } 

    /* Getters and Setters */ 
} 

Alors J'ai créé le référentiel suivant pour la classe Civilian:

public interface CivilianRepository extends GraphRepository<Civilian> { 
    @Query("start n=node(*) where n.firstName=~{0} return n") 
    Page<Civilian> findCiviliansProperties(String firstName, Pageable page);  
} 

Ok. J'ai donc créé quelques Civilian nœuds, et peuplé le graphique avec eux. Il n'y a pas d'autres nœuds dans le graphique, à l'exception des nœuds Civilian. Quand je lance la méthode findCiviliansProperties, je reçois l'exception suivante:

Exception in thread "main" org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node(*) where n.firstName=~{0} return n skip 0 limit 10; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node(*) where n.firstName=~{0} return n skip 0 limit 10; nested exception is org.neo4j.cypher.EntityNotFoundException: The property 'firstName' does not exist on Node[0] 
    at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:52) 
    at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.dispatchQuery(GraphRepositoryQuery.java:98) 
    at org.springframework.data.neo4j.repository.query.GraphRepositoryQuery.execute(GraphRepositoryQuery.java:81) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:312) 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) 
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) 
    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:204) 
    at com.sun.proxy.$Proxy33.findCiviliansProperties(Unknown Source) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
    at java.lang.reflect.Method.invoke(Unknown Source) 
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:198) 
    at com.sun.proxy.$Proxy36.findCiviliansProperties(Unknown Source) 
    at org.technion.socialrescue.playground.Playground.main(Playground.java:38) 
Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement start n=node(*) where n.firstName=~{0} return n skip 0 limit 10; nested exception is org.neo4j.cypher.EntityNotFoundException: The property 'firstName' does not exist on Node[0] 
    at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:63) 
    at org.springframework.data.neo4j.support.query.CypherQueryEngine.query(CypherQueryEngine.java:49) 
    ... 20 more 
Caused by: org.neo4j.cypher.EntityNotFoundException: The property 'firstName' does not exist on Node[0] 
    at org.neo4j.cypher.internal.commands.expressions.Property.apply(Property.scala:35) 
    at org.neo4j.cypher.internal.commands.expressions.Property.apply(Property.scala:29) 
    at org.neo4j.cypher.internal.commands.RegularExpression.isMatch(Predicate.scala:259) 
    at org.neo4j.cypher.internal.pipes.FilterPipe$$anonfun$createResults$1.apply(FilterPipe.scala:29) 
    at org.neo4j.cypher.internal.pipes.FilterPipe$$anonfun$createResults$1.apply(FilterPipe.scala:29) 
    at scala.collection.Iterator$$anon$22.hasNext(Iterator.scala:390) 
    at scala.collection.Iterator$$anon$19.hasNext(Iterator.scala:334) 
    at scala.collection.Iterator$class.isEmpty(Iterator.scala:272) 
    at scala.collection.Iterator$$anon$19.isEmpty(Iterator.scala:333) 
    at org.neo4j.cypher.internal.pipes.SlicePipe.createResults(SlicePipe.scala:32) 
    at org.neo4j.cypher.internal.pipes.ColumnFilterPipe.createResults(ColumnFilterPipe.scala:37) 
    at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$6.apply(ExecutionPlanImpl.scala:127) 
    at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl$$anonfun$6.apply(ExecutionPlanImpl.scala:125) 
    at org.neo4j.cypher.internal.executionplan.ExecutionPlanImpl.execute(ExecutionPlanImpl.scala:33) 
    at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:59) 
    at org.neo4j.cypher.ExecutionEngine.execute(ExecutionEngine.scala:63) 
    at org.neo4j.cypher.javacompat.ExecutionEngine.execute(ExecutionEngine.java:79) 
    at org.springframework.data.neo4j.support.query.CypherQueryEngine.parseAndExecuteQuery(CypherQueryEngine.java:61) 
    ... 21 more 
Caused by: org.neo4j.graphdb.NotFoundException: 'firstName' property not found for NodeImpl#0. 
    at org.neo4j.kernel.impl.core.Primitive.newPropertyNotFoundException(Primitive.java:184) 
    at org.neo4j.kernel.impl.core.Primitive.getProperty(Primitive.java:179) 
    at org.neo4j.kernel.impl.core.NodeImpl.getProperty(NodeImpl.java:52) 
    at org.neo4j.kernel.impl.core.NodeProxy.getProperty(NodeProxy.java:155) 
    at org.neo4j.cypher.internal.commands.expressions.Property.apply(Property.scala:33) 
    ... 38 more 

Donc, la chose la plus importante de cette exception est la ligne suivante - The property 'firstName' does not exist on Node[0] .. Mais comment peut-il être? Il n'y a que Civilian nœuds dans le graphique, et ils ont tous la propriété firstName. Se peut-il que le framework neo4j ajoute d'autres nœuds cachés à mon graphique dont je ne suis pas au courant? Parce que quand je change ma requête en ceci:

start n=node(*) where has(n.firstName) AND n.firstName=~{0} return n 

Tout fonctionne très bien ...

Quel est le problème?

Merci!

Répondre

1

neo4j vient automatiquement avec 1 nœud lorsque vous créez une nouvelle instance, et c'est le nœud de référence. Vous devriez supprimer ceci.

graphDatabaseService.getNodeById(0).delete() 
+0

Mais pourquoi créer ce noeud? – gipouf

+1

@royv Voir cette réponse (http://lists.neo4j.org/pipermail/user/2011-February/006935.html) de l'un des principaux développeurs. – tstorms

+0

Merci! Maintenant, cela a du sens. Mais je m'attendrais à ce que l'utilisateur ajoute ce noeud s'il le souhaite, et non au système pour l'ajouter comme comportement par défaut. Y a-t-il un moyen de créer le graphe sans ce noeud depuis le début? C'est un peu moche d'ajouter cette ligne. – gipouf

Questions connexes