-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
HHH-14097 Fix redundant SQLs issue for fetch entity graph #3453
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
Conversation
271d0ff
to
55d23b0
Compare
documentation/src/test/java/org/hibernate/userguide/fetching/GraphFetchingTest.java
Outdated
Show resolved
Hide resolved
d0577d4
to
4660ca8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure about this, are we entirely sure that the fetch graph is no longer needed at this point?
Wouldn't it be possible for the fetch grapth to need to span multiple load events?
IF this is correct, should line 285 be removed as it seems redundant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For non-toplevel traversal, Line #285 will take effect to backtrack to upper level after the above statement. The above statement will impact only top level (I made it explicitly by including "on top level" in the comments above). I admit the code change is difficult to understand for basically 'fetch graph' implementing is sort of based on hack (existing v5 infrastructure makes it difficult to implement elegantly), but v6 makes the implementation much easier and more elegant (it has well-designed context info accessible). After this PR gets merged, I'll port it into v6 to see whether the issue still remains.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I doubled checked and found the backtracking is working as expected (without it our graph testing cases would fail). Could you take a new look at this PR? Thanks.
Hi @NathanQingyangXu still not sure we really need
if the test is correct, it passes with just
|
4660ca8
to
e7854c4
Compare
The reason your test didn't expose issue might be that |
Thanks @NathanQingyangXu for the additional test, may be I'm missing something but I tried it with just
and it passes. |
e7854c4
to
fc85810
Compare
Sorry for my premature pushing. Now I updated the testing case and I am confident it should be fine. |
fc85810
to
ee82443
Compare
load graph::: | ||
In this case, all attributes specified in the entity graph will be treated as FetchType.EAGER, but attributes not specified use their static mapping specification. | ||
|
||
Below is an `fetch graph` dynamic fetching example: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The above content was copied from v6's counterpart. Thought the basic explanation of the two types of entity graph modes is supposed to exist in v5 as well.
Given the content has existed in v6 already, we don't need to bother merging this part to v6 as well.
if ( fetchGraphContext != null && !fetchGraphContext.appliesTo( entity.getClass() ) ) { | ||
LOG.warnf( "Entity graph specified is not applicable to the entity [%s]. Ignored.", entity); | ||
fetchGraphContext = null; | ||
session.setFetchGraphLoadContext( null ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a minor but I think the session.setFetchGraphLoadContext( null );
is redundant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is necessary because without setting it, the downstream will still try to locate some property as per the context grabbed from session.getFetchGraphLoadContext()
, not from the local variable of fetchGraphContext
. See the org.hibernate.engine.internal.TwoPhaseLoad#isEagerFetchGraph(SharedSessionContractImplementor session, String associationName, Type associationType)
for details.
I am sorry the current fetch entity graph implementation is so difficult to understand (and maintain). Luckily its status is improved much more in v6.
thanks! Merging |
https://hibernate.atlassian.net/browse/HHH-14097
The root cause is we lack fetch entity graph validation. For the initial multiple hydrated objects, only the first one is applicable to root entity graph.
Imported andrea's testing code from #3452. Tons of thanks to him!
Remember only the testing case is needed to be merged into v6 for entity graph implementation is incompatible between v5 and v6 and the code changes except the testing case are not needed in v6 (actually I've carefully deleted the v5 implementation in v6 previously).