0

我的League节点实体如下

@NodeEntity
class League
{
  private Date startDate;
}

我想返回最新的联赛,当从 shell 执行时,以下密码工作正常

START n=node(*) WHERE has(n.__type__) and n.__type__='com.aravind.avl.domain.League' RETURN n ORDER BY n.startDate ASC LIMIT 1

我将其移至存储库,如下所示

public interface LeagueRepository extends GraphRepository<League>
{
    @Query ("START n=node(*) RETURN n ORDER BY n.startDate DESC LIMIT 1")
    League findCurrentLeague();
}

它给了我以下错误。我相信我们不需要像__type__使用存储库时那样提供 spring-data-neo4j 实现细节。想知道如何在不暴露 spring-data-neo4j 实现细节的情况下正确地在存储库中编写查询?

朱尼特

@Test
    public void findCurrentLeague() throws ParseException
    {
        SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");

        League l1 = new League();
        l1.setStartDate(df.parse("01/03/2013"));
        l1.setEndDate(new Date());
        l1.setName("in year 2013");

        League l2 = new League();
        l2.setStartDate(df.parse("01/03/2001"));
        l2.setEndDate(df.parse("01/10/2001"));
        l2.setName("in year 2001");

        repo.save(l1);
        repo.save(l2);

        League currentLeague = repo.findCurrentLeague();
        assertNotNull(currentLeague);
        assertEquals("in year 2013", currentLeague.getName());
    }

错误

Caused by: org.springframework.dao.InvalidDataAccessResourceUsageException: Error executing statement START n=node(*) RETURN n ORDER BY n.startDate DESC LIMIT 1; nested exception is org.neo4j.cypher.EntityNotFoundException: The property 'startDate' 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)
    ... 39 more
Caused by: org.neo4j.cypher.EntityNotFoundException: The property 'startDate' 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.pipes.ExtractPipe$$anonfun$createResults$1$$anonfun$apply$1.apply(ExtractPipe.scala:37)
    at org.neo4j.cypher.internal.pipes.ExtractPipe$$anonfun$createResults$1$$anonfun$apply$1.apply(ExtractPipe.scala:35)
    at scala.collection.immutable.Map$Map1.foreach(Map.scala:118)
    at org.neo4j.cypher.internal.pipes.ExtractPipe$$anonfun$createResults$1.apply(ExtractPipe.scala:35)
    at org.neo4j.cypher.internal.pipes.ExtractPipe$$anonfun$createResults$1.apply(ExtractPipe.scala:34)
    at scala.collection.Iterator$$anon$19.next(Iterator.scala:335)
    at org.neo4j.cypher.internal.pipes.TopPipe.createResults(TopPipe.scala:45)
    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)
    ... 40 more
Caused by: org.neo4j.graphdb.NotFoundException: 'startDate' property not found for NodeImpl#0.
4

2 回答 2

1

此外,SDN 实体,如果它们包含索引属性,则应该有这些属性的索引,让我们针对这些节点:

START n=node:League("name:*") RETURN n ORDER BY n.startDate? DESC LIMIT 1

高温高压

于 2013-06-17T13:57:38.173 回答
0

你在每个节点上都有属性 startDate 吗?异常表明:

Caused by: org.neo4j.cypher.EntityNotFoundException: The property 'startDate' does not exist on Node[0]
    at org.neo4j.cypher.internal.commands.expressions.Property.apply(Property.scala:35)

看起来它在抱怨参考节点。

由于您从使用 node(*) 的所有节点开始,它可能会选择参考节点。如果您不需要它,那么您也许可以摆脱它,或者,如果您在所有节点上都没有 startDate,则可以将您的查询修改为:

START n=node(*) RETURN n ORDER BY n.startDate? DESC LIMIT 1
于 2013-06-14T04:52:59.353 回答