【问题标题】:Spring Data Neo4J 4 - Order By in GraphRepository don't workSpring Data Neo4J 4 - GraphRepository 中的 Order By 不起作用
【发布时间】:2015-07-20 10:37:12
【问题描述】:

要使用 neo4j-graphdatabase 独立服务器,我将 Spring Data Neo4j 4.0.0.M1 的依赖项添加到我的 pom 中。

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-neo4j</artifactId>
    <version>4.0.0.M1</version>
</dependency>

顺便说一句。我编写了自己的 CDI 扩展并在 JavaEE 6 下使用它。 (它已经过测试并且可以工作。)

我在我的应用程序中管理人员。因此,如果我想在 updatedTime 之前获得所有人的订单,我会使用我的PersonRepository (GraphRepository&lt;Person&gt;) 这个简单的查询:

public interface PersonRepository extends GraphRepository<Person> {

    @Query("MATCH (person:Person) " +
            "Return person " +
            "ORDER BY person.updatedTime DESC " +
            "SKIP {0} " +
            "LIMIT {1} ")
    Iterable<Person> findAll(int offset, int maxResults);
}

对于我的测试,我用 3 条语句创建了 3 个人:

1.

"statement":"CREATE (n:Person {createdTime:946717810000,
creator:'test-151658',updatedTime:978340210000,
updater:'test-151658',sic:'sic-141226',gender:'MALE'})"

2.

"statement":"CREATE (n:Person {createdTime:946717810000,
creator:'test-151658',updatedTime:1041412210000,
updater:'test-151658',sic:'sic-141402',gender:'MALE'})"

3。

"statement":"CREATE (n:Person {createdTime:946717810000,
creator:'test-151658',updatedTime:1104570610000,
updater:'test-151658',sic:'sic-105603',gender:'MALE'})"

让所有的人都按我使用的 updatedTime DESC 排序:

Iterable<Person> results = repository.findAll(0, 100);

不要得到

Person 1: updatedTime:1104570610000,
Person 2: updatedTime:1041412210000,
Person 3: updatedTime:978340210000

但是

Person 1: updatedTime:1041412210000,
Person 2: updatedTime:978340210000,
Person 3: updatedTime:1104570610000 

调试它我使用 sudo ngrep -t -d any port 7474

...我的 neo4j-server 的提交很好:

    {"commit":"http://neo4j:7474/db/dat
      a/transaction/833/commit","results":[{"columns":["person"],
    "data":[{"graph":{"nodes":[{"id":"266","labels":["Person"],"properties":{"creator":"test-151658","createdTime":946717810000,
    "updatedTime":1104570610000,
"updater":"test-151658",
    "sic":"sic-105603","gender":"MALE"}}],"relationships":[]}},{"graph":{"nodes":[{"id":"265","labels":["Person"],
    "properties":{"creator":"test-151658",
    "createdTime":946717810000,"updat
          edTime":1041412210000,"updater":"test-151658","sic":"sic-141402","gender":"MALE"}}],
    "relationships":[]}},{"graph":{"nodes":[{"id":"264",
    "labels":["Person"],"properties":{"creator":"test-151658"
    ,"createdTime":
          946717810000,"updatedTime":978340210000,
    "updater":"test-151658","sic":"sic-141226","gender":"MALE"}}],"relationships":[]}}]}],
    "transaction":{"expires":"Mon, 20 Jul 2015 10:03:42 +0000"}
    ,"errors":[]} 

所以现在我的问题是:

1.我怎样才能让我的 3 个人得到正确的排序?

2。这个问题取决于转换为Iterable&lt;Person&gt; 或对象图映射?

3.这个问题取决于我的 neo4j-session 的缓存?

【问题讨论】:

  • 请使用 4.0.0.RC1 - 自 M1 以来有许多修复和功能(包括您可以使用的排序和分页)。如果问题仍然存在,请告诉我们。
  • 谢谢,这解决了我的问题!

标签: java cypher spring-data-neo4j spring-data-neo4j-4


【解决方案1】:

为了方便有类似问题的人,在 4.0.0 M1 之后引入了排序和分页。请使用包含许多错误修复的 4.0.0.RC1。

【讨论】:

    猜你喜欢
    • 2017-01-16
    • 2014-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-18
    • 2018-06-21
    • 1970-01-01
    • 2019-01-27
    相关资源
    最近更新 更多