Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring数据Neo4j-运行密码查询时获取异常_Spring_Neo4j_Spring Data_Spring Data Neo4j - Fatal编程技术网

Spring数据Neo4j-运行密码查询时获取异常

Spring数据Neo4j-运行密码查询时获取异常,spring,neo4j,spring-data,spring-data-neo4j,Spring,Neo4j,Spring Data,Spring Data Neo4j,我在尝试运行简单的密码查询时遇到了一个奇怪的异常。首先,我将介绍我的代码,然后我将展示导致异常的原因。因此,我有以下课程: 表示用户配置文件的简单类: public abstract class Profile extends AbstractEntity { @Indexed ProfileType profileType; @Indexed(indexType = IndexType.FULLTEXT, indexName = "name") String

我在尝试运行简单的密码查询时遇到了一个奇怪的异常。首先,我将介绍我的代码,然后我将展示导致异常的原因。因此,我有以下课程:

表示用户配置文件的简单类:

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 */
}
以及一个简单的类,它继承自
Profile
,表示一个平民:

@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 */
}
嗯。因此,我创建了几个
民用
节点,并用它们填充图形。除
民用
节点外,图中没有其他节点。当我运行
findCiviliansProperties
方法时,我得到以下异常:

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
因此,关于此异常最重要的一点是下面一行-
节点[0]上不存在属性“firstName”
。。但这怎么可能呢?图中只有
民用
节点,它们都具有
firstName
属性。是不是neo4j框架在我的图中添加了一些我不知道的隐藏节点?因为当我将查询更改为以下内容时:

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

怎么了


谢谢

neo4j
在创建新实例时自动附带一个节点,即引用节点。你应该删除这个

graphDatabaseService.getNodeById(0).delete()

但是他们为什么创建这个节点呢?@royv从一个核心开发者那里看到了这个答案()。谢谢!现在它有意义了。但是如果用户愿意,我希望他添加这个节点,而不是系统将其作为默认行为添加。有没有办法从一开始就创建没有此节点的图形?添加这一行有点难看。他们将在不久的将来摆脱这一概念。
graphDatabaseService.getNodeById(0).delete()