Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing error when using Integer ID #18

Closed
colinwebber opened this issue Nov 11, 2013 · 5 comments
Closed

Editing error when using Integer ID #18

colinwebber opened this issue Nov 11, 2013 · 5 comments
Assignees
Labels

Comments

@colinwebber
Copy link

My domain classes use Integer IDs which have become problematic since switching from v1.3.0 to v1.4.1. I tried converting from String to Integer in the beforeSave block, but this isn't invoked until after the problem occurs.

Provided id of the wrong type for class VehicleOfInterest. Expected: class java.lang.Integer, got class java.lang.String. Stacktrace follows:
org.hibernate.TypeMismatchException: Provided id of the wrong type for class VehicleOfInterest. Expected: class java.lang.Integer, got class java.lang.String
    at org.grails.plugin.easygrid.datasource.GormDatasourceService.updateRow(GormDatasourceService.groovy:215)
    at org.grails.plugin.easygrid.EasygridDispatchService.callDSUpdateRow(EasygridDispatchService.groovy:94)
    at org.grails.plugin.easygrid.grids.JqueryGridService.inlineEdit(JqueryGridService.groovy:88)
    at org.grails.plugin.easygrid.EasygridDispatchService.callGridImplInlineEdit(EasygridDispatchService.groovy:48)
    at org.grails.plugin.easygrid.EasygridInitService$_initializeGrids_closure2_closure10_closure14.doCall(EasygridInitService.groovy:76)
    at org.grails.plugin.easygrid.EasygridService.guard(EasygridService.groovy:187)
    at org.grails.plugin.easygrid.EasygridInitService$_initializeGrids_closure2_closure10_closure17_closure18.doCall(EasygridInitService.groovy:103)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:186)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)

From: GormDatasourceService.groovy

    @Transactional
    def updateRow(gridConfig) {
       //
       //  The problem happens here....
       //
        def instance = gridConfig.domainClass.get(params.id)
        if (!instance) {
            return 'default.not.found.message'
        }

        if (params.version) {
            def version = params.version.toLong()
            if (instance.version > version) {
                return 'default.optimistic.locking.failure'
            }
        }

        //default returns params

       //
       //  And the opportunity for conversion is here...
       //
        instance.properties = gridConfig.beforeSave params
        log.debug "instance = $instance"

        if (!instance.save(flush: true)) {
            return instance.errors
        }
    }
@tudor-malene
Copy link
Owner

Umm.
I will need to investigate this.

A quick and dirty fix, so you get this working is to define a closure 'updateRowClosure' in your grid
It would look like this:

updateRowClosure {
        def instance = VehicleOfInterest.get(params.id as Integer)
        if (!instance) {
            return 'default.not.found.message'
        }

        if (params.version) {
            def version = params.version.toLong()
            if (instance.version > version) {
                return 'default.optimistic.locking.failure'
            }
        }

        //call the beforeSave closure directly here - because for some reason the gridConfig is not passed to this closure
        instance.properties = ...
        log.debug "instance = $instance"

        if (!instance.save(flush: true)) {
            return instance.errors
        }
}

This is only temporary, because it will get fixed in the next version.

Let me know how it goes.

Thanks!

@colinwebber
Copy link
Author

It worked - thanks!

@tudor-malene
Copy link
Owner

Great, I will let you know when I release a fix for the underlying issue.

I will reopen the bug, so I can keep track of it.

Thanks.

@tudor-malene tudor-malene reopened this Nov 11, 2013
@ghost ghost assigned tudor-malene Nov 11, 2013
@tudor-malene
Copy link
Owner

This should work in 1.4.2, without the additional code.

@tudor-malene
Copy link
Owner

Closing old issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants