处理GroovyPageView时出错:使用grails注释事务时无法使用next

时间:2015-04-15 16:57:43

标签: grails controller transactional

我有"错误处理GroovyPageView:无法使用next()"如果我在控制器类

中添加注释Transactional,则在我的视图中出错

控制器

@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

1 个答案:

答案 0 :(得分:1)

永远不应该将

@Transactional添加到Grails用于生成控制器的模板中。控制器应该很简单并且可以使用HTTP层,并调用服务来执行事务工作和业务逻辑。从控制器中删除所有@Transactional注释,并将所有保存,更新和删除操作移至一个或多个事务服务,然后将服务依赖注入到控制器中。