Neo4jOperations#queryForObjects()
似乎与@QueryResult
POJO无关 - 它始终表示结果集为空。
尝试Neo4jOperations#queryForObjects
- 它说结果为空:
@Test
public void thisDoesNotWork() {
Iterable<ClassNodeIdAndName> result = neo4jOperations.queryForObjects(
ClassNodeIdAndName.class,
"MATCH (c:ClassNode) RETURN ID(c) AS id, c.name AS name",
new HashMap<>());
assertTrue(result.iterator().hasNext());
}
尝试Neo4jOperations#query
- 说结果不为空:
@Test
public void thisWorksFine() {
Result result = neo4jOperations.query(
"MATCH (c:ClassNode) RETURN ID(c) AS id, c.name AS name",
new HashMap<>());
assertTrue(result.iterator().hasNext());
}
尝试使用@Query
存储库 - 说结果不为空:
@Test
public void thisWorksFineAsWell() {
List<ClassNodeIdAndName> classNodeIdsAndNames = classNodeRepository.getAllIdsAndNames();
assertFalse(classNodeIdsAndNames.isEmpty());
}
public interface ClassNodeRepository extends GraphRepository<ClassNode> {
@Query("MATCH (c:ClassNode) RETURN ID(c) AS id, c.name AS name")
List<ClassNodeIdAndName> getAllIdsAndNames();
}
@QueryResult
public class ClassNodeIdAndName {
public Long id;
public String name;
}
Iterable queryForObjects(Class entityType ,
entityType - 表示要返回的实体类型的类
但我很困惑我是应该查看实体类型还是查看对象。如果它不应该处理@QueryResult
,我会指望它抛出而不是没有返回任何结果。
我使用的是spring-data-neo4j 4.1.3.RELEASE
答案 0 :(得分:1)
#define ALPHABETS_COUNT 26
int commonChars(char *s1, char *s2)
{
int c_count = 0, i;
int arr1[ALPHABETS_COUNT] = {0}, arr2[ALPHABETS_COUNT] = {0};
/* Compute the number of occurances of each character */
while (*s1) arr1[*s1++-'a'] += 1;
while (*s2) arr2[*s2++-'a'] += 1;
/* Increment count based on match found */
for(i=0; i<ALPHABETS_COUNT; i++) {
if(arr1[i] == arr2[i]) c_count += arr1[i];
else if(arr1[i]>arr2[i] && arr2[i] != 0) c_count += arr2[i];
else if(arr2[i]>arr1[i] && arr1[i] != 0) c_count += arr1[i];
}
return c_count;
是Spring Data Neo4j概念,仅适用于Spring @QueryResult
。
Repository
是Neo4j OGM Neo4jOperations
类的一个瘦包装器,因此不处理返回查询结果对象的概念。