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

HHH-14212 Ultimate Fetch Graph fix #3548

Merged
merged 4 commits into from Sep 22, 2020

Conversation

NathanQingyangXu
Copy link
Contributor

@NathanQingyangXu NathanQingyangXu commented Sep 13, 2020

https://hibernate.atlassian.net/browse/HHH-14212

This ticket exposes another regression issue and it forced me to re-consider the previous Fetch Graph implementation I initiated previously. It is becoming more and more difficult to maintain and obviously it is full of bugs and terribly fragile.

Finally I figured out we have a much simpler way to implement Fetch Graph we overlooked previously:

  • revert back all the previous PRs related to Fetch Graph implementation and bug fixing (HHH-8776, HHH-14097, HHH-14124);
  • simply add a logic in TwoPhaseLoad class to check whether Fetch Graph is in effective for now; return false if so in the internal getOverridingEager() method in TwoPhaseLoad class.

The reason is our HQL to SQL step has added all the JOINs already and we simply keep from loading any other entities during hydrating phase. We don't need to duplicate Fetch Graph enforcement for another time! Boom, all of sudden, we solve the Fetch Graph issue in a simple and elegant way. My previous initial implementation is purely misled.

I intentionally organized the commit list to streamline code review. All the commits except the last one are reverting back previous PR commits. You can go to the last commit directly to understand the new implementation: 4685606

// we can return false invariably for if the entity has been covered by entity graph,
// its associated JOIN has been present in the SQL generated and hence it would be loaded anyway
if ( session.isEnforcingFetchGraph() ) {
return false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above one-liner is the gist of the ultimate fix. Its comment is self-explanatory.

Copy link
Member

@yrodiere yrodiere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understand better. Thanks for the clarification. So essentially this leverages the pre-existing "load graph" implementation, adding just one flag in the session to let us know whether we're in "fetch graph" mode or "load graph" mode, and according to that flag we'll decide whether attributes that are not mentioned in the graph are forced to lazy or left to their default value.

Looks good to me!

Copy link
Contributor

@beikov beikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good!

@beikov
Copy link
Contributor

beikov commented Sep 14, 2020

Do we want/need anyone else to review this? If not, I'd say we merge it! 😃

@NathanQingyangXu
Copy link
Contributor Author

Ok, I understand better. Thanks for the clarification. So essentially this leverages the pre-existing "load graph" implementation, adding just one flag in the session to let us know whether we're in "fetch graph" mode or "load graph" mode, and according to that flag we'll decide whether attributes that are not mentioned in the graph are forced to lazy or left to their default value.

Looks good to me!

The session tweaking is not new and it was applied for my previous fix direction (in HHH-8776). What is really inspiring is the simple logic to return 'false' always regardless of whether the entity should be eagerly loaded or not (we have added JOINs for those entity graph nodes already so they will be loaded sooner or later; what really matters is the NEW nodes). The inspiration occurred to me when I was accompanying my little kid in playground. It only took 15 mins to verify my idea. I am really excited by its beauty and simplicity.

@gavinking
Copy link
Member

@NathanQingyangXu so I suppose this one needs to be replicated in Hibernate Reactive?

@gavinking
Copy link
Member

Perhaps it even breaks HR?

@senthilaru
Copy link

When it will be available to the public? I mean the release version.

@NathanQingyangXu
Copy link
Contributor Author

When it will be available to the public? I mean the release version.

guess in next release. @beikov could we have it merged?

@beikov
Copy link
Contributor

beikov commented Sep 22, 2020

What are the concerns here @gavinking ? Do you think that merging this PR will cause problems for HR?

@gavinking
Copy link
Member

No, I'm just saying that we will (I think) need to make changes to HR once this is merged.

@beikov
Copy link
Contributor

beikov commented Sep 22, 2020

I see, thanks for the fast response. I'll merge this then :)

@beikov beikov merged commit 99a4edf into hibernate:master Sep 22, 2020
@NathanQingyangXu
Copy link
Contributor Author

No, I'm just saying that we will (I think) need to make changes to HR once this is merged.

Feel free to ask for my help on that, though I have zero experience on HR right now.

@gavinking
Copy link
Member

@NathanQingyangXu why does this patch remove type arguments and go back there to using raw types?

@gavinking
Copy link
Member

Feel free to ask for my help on that, though I have zero experience on HR right now.

@NathanQingyangXu Well for a start we need to just test HR against the latest ORM snapshot.

@NathanQingyangXu
Copy link
Contributor Author

NathanQingyangXu commented Sep 22, 2020

@NathanQingyangXu why does this patch remove type arguments and go back there to using raw types?

That change is done in yrodiere's PR, which has nothing to do with entity graph. I reverted his PR totally so this change is reverted as well. This PR involves many revertings and I need to be very cautious so I focus on the core issue instead.

@gavinking
Copy link
Member

I reverted his PR totally so this change is reverted as well.

Right, OK, gotcha.

@gavinking
Copy link
Member

HR issue is here hibernate/hibernate-reactive#384

@yrodiere
Copy link
Member

@NathanQingyangXu @beikov Shouldn't this be backported to the 5.4 branch, since the bug was reported on 5.4?

@beikov
Copy link
Contributor

beikov commented Sep 23, 2020

@yrodiere I proposed this to @Sanne and I think he is in the process of testing Quarkus with these changes.

@NathanQingyangXu
Copy link
Contributor Author

NathanQingyangXu commented Sep 28, 2020

@Sanne many people are asking whether we can back port it into 5.4 for it is a regression issue. Seems failure to back port it might hurt our credit for entity graph is a enormously popular feature of JPA.

@Sanne
Copy link
Member

Sanne commented Sep 28, 2020

thanks @NathanQingyangXu , yes I'll backport this. Sorry I've been a bit swamped, hope to "batch" a series of backports so to test them all together in downstream projects.

@chrisknoll
Copy link

Has this been back ported? We're seeing it on v5.4.21, so we're having to downgrade to v5.4.18, but there are other vulnerabilities that were addressed post v5.4.18 so we'd really like to use the latest release int he 5.4.x release.

@yrodiere
Copy link
Member

See https://hibernate.atlassian.net/browse/HHH-14212 . It's been backported in 5.4.22.

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