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

时间:2015-06-16 07:40:44

标签: neo4j spring-data-neo4j

我正在尝试过滤包含用户活动的Feed。我正在使用@QueryResult对象来检索结果。我需要提要和用户喜欢的饲料的关系信息。但是在检索feed时收到错误:org.neo4j.rest.graphdb.entity.RestNode无法强制转换为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 );

1 个答案:

答案 0 :(得分:2)

您的查询返回feed as f,一个节点和rel as r,一个关系。 但是FeedsIterableResult期望它们是集合。每一行&#34;行&#34;该查询返回的内容将包含feed个节点和rel关系。

要匹配您的QueryResult,您必须更改Cypher查询以返回Feed和rels的集合。或者更改FeedsIterableResult以期望单个节点和关系,并让getAllFavoriteFeeds返回FeedsIterableResult的集合。