将LIMIT和OFFSET添加到Grails中的Raw Sql以进行分页

时间:2014-10-23 14:17:17

标签: sql oracle hibernate grails pagination

我有这个原始的sql似乎正在工作。我想在进行分页时为此查询添加限制/偏移量。我正在使用oracle Xe和sql developer for database。我读到在oracle中没有Limit关键字,并且想知道什么是向此查询添加限制/偏移的最佳方法。

final session = sessionFactory.currentSession;
final  String query  = "select distinct a.* from classification c join (select id from taxonomy_node "+ 
                                                        "start with id =:nodeId connect by nocycle prior id = parent_id) h " +
                                                        "on (c.node_id = h.id) join artifact a on (a.id = c.artifact_id) " +
                                                        "Where a.DOCUMENT_ID =:docid AND c.active=1 ";
final sqlQuery = session.createSQLQuery(query);
artifacts = sqlQuery.with {
        addEntity(Artifact);
        setLong('nodeId',filterByAssociatedNodeId as Long);
        setLong('docid',document.id as Long);
        setFirstResult(startIndex);
        setMaxResults(limit);
        list();

}

有类似setMaxResult的东西,但我不认为这对我有帮助,因为我也需要偏移量。我正在为此尝试setFirstResult和setMaxResults。

0 个答案:

没有答案