Quantcast

initialization of associations on validation?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

initialization of associations on validation?

basejump (Josh)
Is there a logic path on why lazy association proxies are initialized?

Using the face nose example
def face = Face.get(1)
//this will not hit the database
assert face.noseId
assert !GrailsHibernateUtil.isInitialized(face,'nose')

//this will now initialize the nose proxy. Why?
face.validate()
assert GrailsHibernateUtil.isInitialized(face,'nose') //database hit occurred and proxy was initialized

Currently in GrailsDomainClassValidator.validate
....
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade) {
        cascadeToAssociativeProperty(errors, bean, persistentProperty);
}
...

I overrode it to be
Boolean isInit = GrailsHibernateUtil.isInitialized(obj,propertyName)
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade && isInit) {
        cascadeToAssociativeProperty(errors, bean, persistentProperty);
}

Can I send a pull request for this change or is there an architectural reason its so aggressive on validation?



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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: initialization of associations on validation?

longwa
What about a case where I assign a nose that's still a proxy? 

face.nose = Nose.load(...)

In this case, what I assign to nose may still be a proxy.

In that case I would expect to get cascading validation for the property. IMO, I think it should be based on whether the property is dirty. In your case, nose hasn't changed so why would validate() need to do anything with it.

On Wed, Jun 20, 2012 at 8:56 PM, Josh (basejump) <[hidden email]> wrote:
Is there a logic path on why lazy association proxies are initialized?

Using the face nose example
def face = Face.get(1)
//this will not hit the database
assert face.noseId
assert !GrailsHibernateUtil.isInitialized(face,'nose')

//this will now initialize the nose proxy. Why?
face.validate()
assert GrailsHibernateUtil.isInitialized(face,'nose') //database hit occurred and proxy was initialized

Currently in GrailsDomainClassValidator.validate
....
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade) {
       cascadeToAssociativeProperty(errors, bean, persistentProperty);
}
...

I overrode it to be
Boolean isInit = GrailsHibernateUtil.isInitialized(obj,propertyName)
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade && isInit) {
       cascadeToAssociativeProperty(errors, bean, persistentProperty);
}

Can I send a pull request for this change or is there an architectural reason its so aggressive on validation?



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

   http://xircles.codehaus.org/manage_email



Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: initialization of associations on validation?

basejump (Josh)
you would still get validation for the property. It does that first. The change simply stops the cascading validation if the proxy is not initialized. In your case nose has not changed either right and is still a proxy? So no need to validate it. 


On Jun 20, 2012, at 8:28 PM, Aaron Long wrote:

What about a case where I assign a nose that's still a proxy? 

face.nose = Nose.load(...)

In this case, what I assign to nose may still be a proxy.

In that case I would expect to get cascading validation for the property. IMO, I think it should be based on whether the property is dirty. In your case, nose hasn't changed so why would validate() need to do anything with it.

On Wed, Jun 20, 2012 at 8:56 PM, Josh (basejump) <[hidden email]> wrote:
Is there a logic path on why lazy association proxies are initialized?

Using the face nose example
def face = Face.get(1)
//this will not hit the database
assert face.noseId
assert !GrailsHibernateUtil.isInitialized(face,'nose')

//this will now initialize the nose proxy. Why?
face.validate()
assert GrailsHibernateUtil.isInitialized(face,'nose') //database hit occurred and proxy was initialized

Currently in GrailsDomainClassValidator.validate
....
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade) {
       cascadeToAssociativeProperty(errors, bean, persistentProperty);
}
...

I overrode it to be
Boolean isInit = GrailsHibernateUtil.isInitialized(obj,propertyName)
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade && isInit) {
       cascadeToAssociativeProperty(errors, bean, persistentProperty);
}

Can I send a pull request for this change or is there an architectural reason its so aggressive on validation?



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

   http://xircles.codehaus.org/manage_email




Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: initialization of associations on validation?

longwa
I see. So we would validate, for example, that face.nose is non-null, etc, but not cascade to the Nose since it's not been unwrapped. So the assumption is that if it's still a proxy, it can't possibly be dirty and therefore doesn't need validation. Makes sense.

On Wed, Jun 20, 2012 at 9:41 PM, Josh (basejump) <[hidden email]> wrote:
you would still get validation for the property. It does that first. The change simply stops the cascading validation if the proxy is not initialized. In your case nose has not changed either right and is still a proxy? So no need to validate it. 


On Jun 20, 2012, at 8:28 PM, Aaron Long wrote:

What about a case where I assign a nose that's still a proxy? 

face.nose = Nose.load(...)

In this case, what I assign to nose may still be a proxy.

In that case I would expect to get cascading validation for the property. IMO, I think it should be based on whether the property is dirty. In your case, nose hasn't changed so why would validate() need to do anything with it.

On Wed, Jun 20, 2012 at 8:56 PM, Josh (basejump) <[hidden email]> wrote:
Is there a logic path on why lazy association proxies are initialized?

Using the face nose example
def face = Face.get(1)
//this will not hit the database
assert face.noseId
assert !GrailsHibernateUtil.isInitialized(face,'nose')

//this will now initialize the nose proxy. Why?
face.validate()
assert GrailsHibernateUtil.isInitialized(face,'nose') //database hit occurred and proxy was initialized

Currently in GrailsDomainClassValidator.validate
....
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade) {
       cascadeToAssociativeProperty(errors, bean, persistentProperty);
}
...

I overrode it to be
Boolean isInit = GrailsHibernateUtil.isInitialized(obj,propertyName)
if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade && isInit) {
       cascadeToAssociativeProperty(errors, bean, persistentProperty);
}

Can I send a pull request for this change or is there an architectural reason its so aggressive on validation?



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

   http://xircles.codehaus.org/manage_email





Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: initialization of associations on validation?

Graeme Rocher-4
Administrator
In reply to this post by basejump (Josh)
On Thu, Jun 21, 2012 at 2:56 AM, Josh (basejump) <[hidden email]> wrote:

> Is there a logic path on why lazy association proxies are initialized?
>
> Using the face nose example
> def face = Face.get(1)
> //this will not hit the database
> assert face.noseId
> assert !GrailsHibernateUtil.isInitialized(face,'nose')
>
> //this will now initialize the nose proxy. Why?
> face.validate()
> assert GrailsHibernateUtil.isInitialized(face,'nose') //database hit occurred and proxy was initialized
>
> Currently in GrailsDomainClassValidator.validate
> ....
> if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade) {
>        cascadeToAssociativeProperty(errors, bean, persistentProperty);
> }
> ...
>
> I overrode it to be
> Boolean isInit = GrailsHibernateUtil.isInitialized(obj,propertyName)
> if ((persistentProperty.isAssociation() || persistentProperty.isEmbedded()) && cascade && isInit) {
>        cascadeToAssociativeProperty(errors, bean, persistentProperty);
> }
>
> Can I send a pull request for this change or is there an architectural reason its so aggressive on validation?
>

Sure pull requests welcome. Note that you cannot introduce a
dependency on hibernate in grails-core so you you may need to use the
ProxyHandler interface instead

Cheers

>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>



--
Graeme Rocher
Grails Project Lead
SpringSource - A Division of VMware
http://www.springsource.com

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

    http://xircles.codehaus.org/manage_email


Loading...