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

hibernate >= 3.6.10.17 doesnt support fields named 'target' #58

Closed
kimmob opened this issue Mar 30, 2015 · 0 comments
Closed

hibernate >= 3.6.10.17 doesnt support fields named 'target' #58

kimmob opened this issue Mar 30, 2015 · 0 comments

Comments

@kimmob
Copy link

kimmob commented Mar 30, 2015

We have a problem that appears if we use

compile ":hibernate:3.6.10.18"

but is ok with

compile ":hibernate:3.6.10.17"

It seems to be because of this commit

0a24b76#diff-b9a5a8c718a76728eab6fcf82cf4212b

If we have a field named 'target' that is lazy-loaded, we get a ClassCastException because the object itself is returned instead of the field.

Probably because this code is called earlier now (see github-link)

    } else if (property.equals("target")) {
        return getProxyTarget(self);
    } else {

It's very easy to reproduce. This snippet will not work.

    def order = Order.load(1)
    def t = order.target

But this will.

    def order = Order.get(1)
    def t = order.target

If accessing the field and not knowing how it was loaded it's a confusing error.

When it's not lazy-loaded it doesn't happen, so it can be hard to find.

So I think all projects that use a field named target that sometimes loads lazy will break.

Lari suggests target is renamed proxyTarget in EntityProxy some day.
( https://groups.google.com/forum/#!topic/grails-dev-discuss/Vq-c1oTyKjo )

That would be good. Until then I think a compile-time-warning for fields named target or even a compile-time-error would be necessary. And this behaviour documented.

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

No branches or pull requests

2 participants