处理 GroovyPageView 时出错:无法使用 grails 注释事务推进使用下一步

Error processing GroovyPageView: could not advance using next using grails annotation transaction

如果我向控制器添加注释事务 class

,我的视图会出现 "Error processing GroovyPageView: could not advance using next()" 错误

控制器

@Transactional(readOnly = true)
class SomeController {
    ...
    def sessionFactory

    def list(){
        def list = sessionFactory.currentSession.createSQLQuery( "some_query" ).scroll()

        [ list : list ]
    }
}

查看

...
<g:while test="${ list?.next() }"> <%-- exception here --%>
    <g:set var="instance" value="${ list.get() }"/>
...

如果我删除 @Transactional(readOnly = true) 一切正常,有人知道如何在视图中使用滚动配置事务注释吗?

注意: 我使用 grails 2.4.4

更新 我尝试了这三个,但没有,同样的错误;

@Transactional
class SomeController {
...
@Transactional(readOnly = true)
class SomeController {

    @Transactional(readOnly = false)
    def list(){
...
@Transactional(readOnly = false)
class SomeController {

    @Transactional(readOnly = false)
    def list(){

这里整个错误:

2015-04-15 15:22:50,402 [http-bio-8080-exec-8] ERROR errors.GrailsExceptionResolver  - PSQLException occurred when processing request: [GET] /app
This ResultSet is closed.. Stacktrace follows:
Message: Error processing GroovyPageView: could not advance using next()
    Line | Method
->>  257 | doFilter  in \grails-app\views\some\list.gsp

Caused by GenericJDBCException: could not advance using next()
->>  265 | doCall    in list_gsp$_run_closure2
|    291 | run       in list_gsp
|    198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|     53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|     76 | doFilter  in org.jasig.cas.client.session.SingleSignOutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread

Caused by PSQLException: This ResultSet is closed.
->> 2852 | checkClosed in org.postgresql.jdbc2.AbstractJdbc2ResultSet
|   1890 | next      in     ''
|    265 | doCall .  in list_gsp$_run_closure2
|    291 | run       in list_gsp
|    198 | doFilter  in grails.plugin.cache.web.filter.PageFragmentCachingFilter
|     63 | doFilter  in grails.plugin.cache.web.filter.AbstractFilter
|     53 | doFilter  in grails.plugin.springsecurity.web.filter.GrailsAnonymousAuthenticationFilter
|     49 | doFilter  in grails.plugin.springsecurity.web.authentication.RequestHolderAuthenticationFilter
|     82 | doFilter  in grails.plugin.springsecurity.web.authentication.logout.MutableLogoutFilter
|     76 | doFilter  in org.jasig.cas.client.session.SingleSignOutFilter
|   1145 | runWorker in java.util.concurrent.ThreadPoolExecutor
|    615 | run       in java.util.concurrent.ThreadPoolExecutor$Worker
^    745 | run . . . in java.lang.Thread

@Transactional 永远不应该添加到 Grails 用来生成控制器的模板中。控制器应该简单并与 HTTP 层一起工作,并调用服务来完成事务工作和业务逻辑。从您的控制器中删除所有 @Transactional 注释,并将所有保存、更新和删除移动到一个或多个事务服务,然后将服务依赖注入到您的控制器中。