获取错误 org.neo4j.rest.graphdb.entity.RestNode 无法转换为 java.lang.Iterable

Getting error org.neo4j.rest.graphdb.entity.RestNode cannot be cast to java.lang.Iterable

我正在尝试过滤包含用户活动的供稿。我正在使用 @QueryResult 对象来检索结果。我需要提要和用户喜欢的提要的关系信息。但是在检索提要时出现错误:org.neo4j.rest.graphdb.entity.RestNode cannot be cast to java.lang.Iterable。 (我使用的是 SDN 3.3.0.RELEASE 和 neo4j 2.1.7)

@QueryResult
public interface FeedsIterableResult {
        @ResultColumn("f")
        Collection<Feed> getFeeds();

        @ResultColumn("r")
        Collection<UserInspiredByFeed> getPaths();
    }

@Query("match (feed:Feed)-[:FEED_CONTAINS_TAG]->(t:Tag)<-[:USER_FAVORITED_TAG]-(u:User{username:{1}}) "
            + "where feed.feedType in {0} "
            + "with u, feed "
            + "optional match (u)-[rel:USER_LIKED_FEED]->(feed) "
            + "return feed as f, rel as r "
            + "union match (u:User{username:{1}})-[:USER_FAVORITED_USER]->(u2:User)-[:USER_LIKED_FEED|:USER_CREATED_FEED]->(feed:Feed) "
            + "where feed.feedType in {0} "
            + "with u2, feed "
            + "optional match (u2)-[rel:USER_LIKED_FEED]->(feed) "
            + "return feed as f, rel as r "         
            + "order by f.timeAdded desc "
            + "skip {2} limit {3}")
FeedsIterableResult getAllFavoriteFeeds(String[] typeFilter, String userName, int skip, int limit);

如果我按照 Luanne 的建议转换查询,我会收到以下错误: 类型不匹配:应为地图、节点或关系但为集合。

新查询:

    @QueryResult
    public interface FeedsIterableResult {
        @ResultColumn("f")
        List<Feed> getFeeds();

        @ResultColumn("r")
        List<UserInspiredByFeed> getPaths();
    }

@Query("match (feed:Feed)-[:FEED_CONTAINS_TAG]->(t:Tag)<-[:USER_FAVORITED_TAG]-(u:User{username:{1}}) "
            + "where feed.feedType in {0} "
            + "with u, feed "
            + "optional match (u)-[rel:USER_INSPIREDBY_FEED]->(feed) "
            + "return collect(feed) as f, collect(rel) as r "
            + "union match (u:User{username:{1}})-[:USER_FAVORITED_USER]->(u2:User)-[:USER_INSPIREDBY_FEED|:USER_CREATED_FEED]->(feed:Feed) "
            + "where feed.feedType in {0} "
            + "with u2, feed "
            + "optional match (u2)-[rel:USER_INSPIREDBY_FEED]->(feed) "
            + "return collect(feed) as f, collect(rel) as r "           
            + "order by f.timeAdded desc "
            + "skip {2} limit {3}")
FeedsIterableResult getAllFavoriteFeeds(String[] typeFilter, String userName, int skip, int limit );

您的查询 returns feed as f,一个节点,和 rel as r,一个关系。 但是 FeedsIterableResult 期望它们是集合。该查询的每个 "row" return 将包含一个 feed 节点和一个 rel 关系。

要匹配您的 QueryResult,您必须将 Cypher 查询更改为 return 提要和 rels 集合。或者更改 FeedsIterableResult 以期望单个节点和关系并具有 getAllFavoriteFeeds return FeedsIterableResult.

的集合