respect NO_PROXY for polymorphic associations #5591
Closed
gavinking
started this conversation in
Design Proposals
Replies: 1 comment 4 replies
-
Most of what I wrote above is garbage because it presupposed that our "no proxy" laziness was based on interception on the owner entity side. But actually that's not how it works at all, and so:
So actually, now that I understand it properly, I think the current behavior is sort-of fine. But we should make it an error to write |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Alright, so, I've always been against the "no proxy" style of lazy fetching, since it means you can't get the foreign key of an associated entity without fetching the entity. Which is stupid, because the FK is sitting right there.
(Even introducing a static
Hibernate.getId()
method would not work since the field is probablyprivate
and hidden behind a getter that would trigger fetching.)But, on the other hand, I'm not happy at all with how we currently treat
@LazyToOne(NO_PROXY)
. The current behavior in 6, and according to my tests (though contrary to what is claimed in a bug report), also in 5, is that for a lazy polymorphic association we just ignoreNO_PROXY
and fall back to using a proxy.I don't think that can possibly be the best thing, and one of the following is what should happen. Either we should:
@LazyToOne
annotation andNO_PROXY
altogether.To be clear, 3 would be perfectly fine by me. But if we're going to have it, we should make sure it doesn't suck.
At first I started arguing it would be a bad idea to do lazy fetching of polymorphic associations based on field access on the owning side of the association, but actually that's a garbage argument here, since we already do it for lazy fields, and anyway, even proxies break if your entity has
public
fields. Plus we have "extended" bytecode enhancement where even this is perfectly safe. And we use it in Quarkus.So, no, that was wrong: the real reason we've always disfavored this implementation is that we want efficient access to the id without hitting the database, not anything about field interception being dangerous. I remember now.
So after chatting with @beikov I think we've agreed that this can actually be implemented, but only by a funny process where:
The question is whether doing this work is worth the benefit to users, given that we don't think this is a terribly great feature to begin with. (If it were up to me, my inclination would be to just deprecate that annotation, if we're not going to sit down and do the work.)
WDYT @sebersole @beikov @Sanne ?
Beta Was this translation helpful? Give feedback.
All reactions