当前位置: 首页 > 知识库问答 >
问题:

重现cypher最新联赛

全飞扬
2023-03-14

我有下面的联盟节点实体

@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();
}

它给我下面的错误。我相信我们在使用存储库时不需要提供spring-data-neo4j实现细节,如__type__。想知道如何在不暴露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.

共有2个答案

贺彬
2023-03-14

是否在每个节点上都有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)

它似乎在抱怨引用节点。

由于您使用节点(*)在所有节点上启动,因此它可能会拾取引用节点。如果不需要它,则可以将其删除,或者,如果所有节点上都没有startDate,则可以将查询修改为:

START n=node(*) RETURN n ORDER BY n.startDate? DESC LIMIT 1
史洛城
2023-03-14

此外,SDN实体如果包含索引属性,则应该有这些属性的索引,让您以这些节点为目标:

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

HTH公司

 类似资料:
  • 本文向大家介绍SpringBoot发现最新版Druid重大问题(坑),包括了SpringBoot发现最新版Druid重大问题(坑)的使用技巧和注意事项,需要的朋友参考一下 发现Druid问题 最近做项目,遇到大量插入的地方,经过大量的调试,最终发现是Druid连接池的问题,(以前一个大项目就遇到过Druid的坑),果断换成c3p0之后,压力测试哗哗上去了。 下面是更换c3p0方法。 1.修改pom

  • 但没有成功。 我用的是3.0版。*Neo4j,Cypher 3.0,Ubuntu 4.14服务器。

  • 我正在使用直接通过管道传输到neo4j-shell中的密码命令加载一个Neo4j数据库。一些实验表明,大约1000行的子图批给出了最佳吞吐量(大约3.2ms/行,300行/秒(慢!),Neo4j 2.0.1)。我使用MATCH语句将现有节点绑定到加载子图。下面是一个截断的例子:

  • docker pull 这个命令 我当时想的是拉取最新版本的镜像 结果发现tag是latest 但是版本不是最新的 dockerhub库中有最新的 这是不是说明我的docker拉取的仓库不对啊 怎么修改 或配置 我配置了阿里加速 下面是配置的阿里的

  • 问题内容: 我有一个问题,我通过沿行轴串联(垂直堆叠)来生成熊猫数据框。 每个组成数据帧都有一个自动生成的索引(升序编号)。 串联后,我的索引被搞砸了:它的计数最多为n(其中n是相应数据帧的shape [0]),并在下一个数据帧从零重新开始。 我正在尝试“根据给定的当前顺序重新计算索引”或“重新索引”(或者我认为)。事实证明,这似乎并没有在做。 这是我尝试做的事情: 它失败并显示“无法从重复的轴重

  • 本文向大家介绍Ajax实现不刷新取最新商品,包括了Ajax实现不刷新取最新商品的使用技巧和注意事项,需要的朋友参考一下 话不多说,请看代码: HTML 的内容 实例2:根据输入的ID 获取商品信息 并修改 HTML端的内容 以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持呐喊教程!