Strange Behaviour

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Strange Behaviour

Guilherme Loch Waltrick Góes
I have this code on my RegisterUserController :

    def approve = {
        params.each({
            String s = it
            if(s.substring(0,2).equals("id")) {
                def approvedUser = RegisterUser.get( params.id )
                def newUser = new User(approvedUser.properties)
                newUser.save()
                approvedUser.delete()
                if(flash.message == null) {
                    flash.message = "Added user ${newUser}"
                } else {
                    flash.message += ", ${newUser}"
                }
            }
        })

When I try to call the approve action on this controller I get the following error:

[118710] errors.GrailsExceptionResolver org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
org.codehaus.groovy.runtime.InvokerInvocationException: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
at org.jsecurity.web.servlet.WebInterceptorFilter.doFilterInternal(WebInterceptorFilter.java:106)
at org.jsecurity.web.servlet.SecurityContextFilter.doFilterInternal(SecurityContextFilter.java:93)
at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:106)
Caused by: org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.
at RegisterUserController$_closure9_closure10.doCall(RegisterUserController.groovy:134)
at RegisterUserController$_closure9.doCall(RegisterUserController.groovy:125)
at RegisterUserController$_closure9.doCall(RegisterUserController.groovy)
... 3 more

I never changed the FlushMode anywhere, what should I do ?

Best Regards,

--
Guilherme Loch Góes

Visite nossa loja virtual: http://www.shopvoip.com.br

Notícias e Fórum sobre VoIP com software livre: http://www.asteriskexperts.com.br
Reply | Threaded
Open this post in threaded view
|

Re: Strange Behaviour

burtbeckwith
Move the code to a transactional service. Spring's transaction support changes
the flush mode for you.

Burt

On Thursday 28 February 2008 2:25:03 pm Guilherme Loch Waltrick Góes wrote:

> I have this code on my RegisterUserController :
>     def approve = {
>         params.each({
>             String s = it
>             if(s.substring(0,2).equals("id")) {
>                 def approvedUser = RegisterUser.get( params.id )
>                 def newUser = new User(approvedUser.properties)
>                 newUser.save()
>                 approvedUser.delete()
>                 if(flash.message == null) {
>                     flash.message = "Added user ${newUser}"
>                 } else {
>                     flash.message += ", ${newUser}"
>                 }
>             }
>         })
>
> When I try to call the approve action on this controller I get the
> following error:
>
> [118710] errors.GrailsExceptionResolver
> org.springframework.dao.InvalidDataAccessApiUsageException: Write
> operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn
> your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from
> transaction definition.
> org.codehaus.groovy.runtime.InvokerInvocationException:
> org.springframework.dao.InvalidDataAccessApiUsageException: Write
> operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn
> your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from
> transaction definition.
> at org.jsecurity.web.servlet.WebInterceptorFilter.doFilterInternal(
> WebInterceptorFilter.java:106)
> at org.jsecurity.web.servlet.SecurityContextFilter.doFilterInternal(
> SecurityContextFilter.java:93)
> at org.jsecurity.web.servlet.OncePerRequestFilter.doFilter(
> OncePerRequestFilter.java:106)
> Caused by: org.springframework.dao.InvalidDataAccessApiUsageException:
> Write operations are not allowed in read-only mode
> (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or
> remove 'readOnly' marker from transaction definition.
> at RegisterUserController$_closure9_closure10.doCall(
> RegisterUserController.groovy:134)
> at RegisterUserController$_closure9.doCall(RegisterUserController.groovy
>
> :125)
>
> at RegisterUserController$_closure9.doCall(RegisterUserController.groovy)
> ... 3 more
>
> I never changed the FlushMode anywhere, what should I do ?
>
> Best Regards,



---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email