atom feed3 messages in org.codehaus.grails.devRe: [grails-dev] Updating objects wit...
FromSent OnAttachments
Robert FletcherJul 29, 2009 4:10 am 
Jesse O'Neill-OineAug 14, 2009 9:50 am 
Robert FletcherAug 16, 2009 10:53 pm 
Subject:Re: [grails-dev] Updating objects with data that violates constraints (GRAILS-4753)
From:Robert Fletcher (
Date:Aug 16, 2009 10:53:39 pm

I committed a fix that went in to Grails 1.2-M2

On Fri, Aug 14, 2009 at 5:50 PM, Jesse O'Neill-Oine<> wrote:

Are there any good workarounds other than patching Grails? Jesse

On Wed, Jul 29, 2009 at 6:10 AM, Robert Fletcher <> wrote:

We've just been looking into this bug and I think we've discovered the cause of the problem. In GrailsDomainClassValidator the method getAssociatedDomainClass is used to figure out what domain class to cascade the validation to:

private GrailsDomainClass getAssociatedDomainClass(Object associatedObject, GrailsDomainClassProperty persistentProperty) {        if(persistentProperty.isEmbedded()) {            return persistentProperty.getComponent();        }        else {            if(grailsApplication!=null)                return (GrailsDomainClass) grailsApplication.getArtefact(DomainClassArtefactHandler.TYPE, associatedObject.getClass().getName());            else                return persistentProperty.getReferencedDomainClass();        }    }

However when associatedObject is a javaassist proxy (which happens when loading an existing instance of the owning class even when the property is lazy: false which surprised me) the call to grailsApplication.getArtefact returns null. The validator then can't proceed to cascade validation down to the associated object - hence the object can get updated with data that violates its constraints.

It looks like just always using persistentProperty.getReferencedDomainClass() would always work but I'm just not sure whether there's some good reason that's not being done. Can anyone enlighten us?

Cheers, Rob & James