0

我在我的网站中使用 Spring Data Neo4j 3.0.0。

我在开发时遇到了一些问题。我在@NodeEntity 模型类中使用@Query Annontation。

@Query(value = "START a=node({self}) MATCH (a)<-[:`COMMENT_TO`]-(b) RETURN b ORDER BY    b.createdAt DESC")
private Set<BaseComment> sortedComments;

我尝试使用这个结果......然后 sortedComments 类型是 SpringEndResult。我如何使用这个结果来设置?

我可以在.jsp 中使用它吗?当我在带有 JSTL(c:foreach) 的 jsp 中使用 sortedComments 时。我遇到 SpringEndResult 没有属性异常。

我不是英语本地人。感谢您的答复。:)

@Test
public void getList() {
    List<SimpleArticle> articles = articleService.getAll(0, 10).getContent();
    for (SimpleArticle simpleArticle : articles) {
        Set<BaseComment> comments = simpleArticle.getSortedComments();
        for (BaseComment baseComment : comments) {
            log.info(baseComment);
        }
    }
}

而我遇见了

java.lang.ClassCastException: org.springframework.data.neo4j.rest.SpringEndResult cannot be cast to kr.carcare.model.bbs.BaseComment

这是我的域类

public class SimpleArticle extends BaseArticle {

@RelatedTo(type = "COMMENT_TO", direction = Direction.INCOMING)
@Fetch
private Set<BaseComment> comments;

@Query("START a=node({self}) MATCH (a)<-[:`COMMENT_TO`]-(b) RETURN b ORDER BY b.createdAt DESC")
private Set<BaseComment> sortedComments;
4

1 回答 1

1

尝试使用 SpringEndResult 的“as”方法并为其提供类似 Set.class 的内容(或类似的实现 Iterable 的内容)。

我不记得这是否是确切的语法,但是,“as”方法采用扩展 Iterable 的类参数,其中 R 是模板类型;在您的情况下,R 是 BaseComment。

于 2014-05-09T02:21:09.190 回答