GORM Javassist proxies / forcing eager load

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

GORM Javassist proxies / forcing eager load

Marc Palmer Local
Hi,

Is there a quick and easy way to force eager load on all the (direct) associations of an object?

I need to edit master/detail in the same form and am getting proxies back from a model (which I can't control) for the associations, and would rather I had all the data to start with when the controller action executes :)

Alternatively, a way to get to the original class that the javassist proxy is wrapping would unblock me...

BTW in investigating this I found that "fetch" for finders is not documented in grails docs, and now is instanceOf method.

Thanks in advance,
Marc
~ ~ ~
Marc Palmer
Blog         > http://www.anyware.co.uk
Twitter      > http://twitter.com/wangjammer5
Grails Rocks > http://www.grailsrocks.com







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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: GORM Javassist proxies / forcing eager load

smaldini
I think the Domain.get() unwraps the proxy, but I have doubts about collections.

On Fri, May 7, 2010 at 1:02 PM, Marc Palmer <[hidden email]> wrote:
Hi,

Is there a quick and easy way to force eager load on all the (direct) associations of an object?

I need to edit master/detail in the same form and am getting proxies back from a model (which I can't control) for the associations, and would rather I had all the data to start with when the controller action executes :)

Alternatively, a way to get to the original class that the javassist proxy is wrapping would unblock me...

BTW in investigating this I found that "fetch" for finders is not documented in grails docs, and now is instanceOf method.

Thanks in advance,
Marc
~ ~ ~
Marc Palmer
Blog         > http://www.anyware.co.uk
Twitter      > http://twitter.com/wangjammer5
Grails Rocks > http://www.grailsrocks.com







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

   http://xircles.codehaus.org/manage_email





--
Stéphane MALDINI
doc4web consultant
[hidden email]
--
http://fr.linkedin.com/in/smaldini
Reply | Threaded
Open this post in threaded view
|

Re: GORM Javassist proxies / forcing eager load

Marc Palmer Local

On 7 May 2010, at 12:28, Stephane Maldini wrote:

> I think the Domain.get() unwraps the proxy, but I have doubts about collections.

It doesn't unwrap associations - it can't if they lazy load.

The problem is finding out the original class of the association, without having to go back to the GrailsDomainClass

Marc


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: GORM Javassist proxies / forcing eager load

Graeme Rocher-3
In reply to this post by Marc Palmer Local
Use a join query so that you get actual instances back and not proxies

Cheers

On 7 May 2010, at 13:02, Marc Palmer wrote:

> Hi,
>
> Is there a quick and easy way to force eager load on all the (direct) associations of an object?
>
> I need to edit master/detail in the same form and am getting proxies back from a model (which I can't control) for the associations, and would rather I had all the data to start with when the controller action executes :)
>
> Alternatively, a way to get to the original class that the javassist proxy is wrapping would unblock me...
>
> BTW in investigating this I found that "fetch" for finders is not documented in grails docs, and now is instanceOf method.
>
> Thanks in advance,
> Marc
> ~ ~ ~
> Marc Palmer
> Blog         > http://www.anyware.co.uk
> Twitter      > http://twitter.com/wangjammer5
> Grails Rocks > http://www.grailsrocks.com
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: GORM Javassist proxies / forcing eager load

Marc Palmer Local

On 7 May 2010, at 13:31, Graeme Rocher wrote:

> Use a join query so that you get actual instances back and not proxies

Yes... but that means you have to look at the persistent properties of the artefact to find out what the associations are to load eagerly.

If you have a proxy, you can't get the artefact class to do that - well I couldn't find a way.

Luckily we know the name of the class being edited in our controller so I can bypass this problem, but it doesn't feel very good.

Marc
~ ~ ~
Marc Palmer
Blog         > http://www.anyware.co.uk
Twitter      > http://twitter.com/wangjammer5
Grails Rocks > http://www.grailsrocks.com


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

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: GORM Javassist proxies / forcing eager load

Daniel Honig
I've never liked using this, but there is the painfully handy:

   GrailsHibernateUtil.unwrapProxy(o)



On Fri, May 7, 2010 at 10:37 AM, Marc Palmer <[hidden email]> wrote:

>
> On 7 May 2010, at 13:31, Graeme Rocher wrote:
>
>> Use a join query so that you get actual instances back and not proxies
>
> Yes... but that means you have to look at the persistent properties of the artefact to find out what the associations are to load eagerly.
>
> If you have a proxy, you can't get the artefact class to do that - well I couldn't find a way.
>
> Luckily we know the name of the class being edited in our controller so I can bypass this problem, but it doesn't feel very good.
>
> Marc
> ~ ~ ~
> Marc Palmer
> Blog         > http://www.anyware.co.uk
> Twitter      > http://twitter.com/wangjammer5
> Grails Rocks > http://www.grailsrocks.com
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

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

    http://xircles.codehaus.org/manage_email