cflorenciav
cflorenciav

Reputation: 439

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

I have "Error processing GroovyPageView: could not advance using next()" error in my view if I add annotation Transactional to controller class

Controller

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

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

        [ list : list ]
    }
}

View

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

If I remove @Transactional(readOnly = true) works all ok, does anybody knows how to configure transactional annotation using scrolls in views?

NOTE: I use grails 2.4.4

UPDATE I tried with these three and nothing, same error;

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

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

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

Here whole error:

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

Upvotes: 1

Views: 269

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75681

@Transactional should never have been added to the templates that Grails uses to generate controllers. Controllers should be simple and work with the HTTP layer, and call services to do transactional work and business logic. Remove all @Transactional annotations from your controllers and move all saves, updates, and deletes to one or more transactional services, then dependency-inject the service(s) into your controllers.

Upvotes: 1

Related Questions