Spring Data Neo4J 4 - GraphRepository 中的排序方式不起作用
Spring Data Neo4J 4 - Order By in GraphRepository don't work
为了使用 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-Extension 并在 JavaEE 6 下使用它。
(它已经过测试并且有效。)
我在我的应用程序中管理人员。因此,如果我想在更新时间之前让所有人下订单,我会在 PersonRepository (GraphRepository<Person>)
:
中使用这个简单的查询
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'})"
让所有人按我使用的更新时间 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<Person>
或对象图映射?
3。这个问题取决于我的 neo4j-session 的缓存吗?
为了有类似问题的人,排序和分页是在4.0.0 M1之后引入的。请使用 4.0.0.RC1,它也包含许多错误修复。
为了使用 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-Extension 并在 JavaEE 6 下使用它。 (它已经过测试并且有效。)
我在我的应用程序中管理人员。因此,如果我想在更新时间之前让所有人下订单,我会在 PersonRepository (GraphRepository<Person>)
:
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'})"
让所有人按我使用的更新时间 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<Person>
或对象图映射?
3。这个问题取决于我的 neo4j-session 的缓存吗?
为了有类似问题的人,排序和分页是在4.0.0 M1之后引入的。请使用 4.0.0.RC1,它也包含许多错误修复。