Skip to content

Fix caching of OneToOneType from second level cache. #3590

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

Merged
merged 4 commits into from
Nov 4, 2020

Conversation

deAtog
Copy link

@deAtog deAtog commented Oct 9, 2020

This fixes issue HHH-14216. Changes are based on the ManyToOneType and make it so that when the cached Id is null, it is reliably so. This fixes an otherwise expensive query that occurs to verify the associated one-to-one entity is null when the OneToOneType Id is null.

@NathanQingyangXu
Copy link
Contributor

Thanks for the PR. As a general rule, we require JIRA ticket id showing up as git commit prefix so we can correlate git commit to its ticket easily. Including it in PR title is recommended but not required.

@NathanQingyangXu
Copy link
Contributor

NathanQingyangXu commented Oct 10, 2020

Please come up with a compelling testing case (or suite) to demonstrate that

  1. Without your code changes, the testing would fail;
  2. With your code changes, the testing would succeed.

This is invaluable both in vallidation and long-term maintaining. Feature PR without testing case would be seen as incomplete work. Please see existing testing cases for example or template.

@deAtog
Copy link
Author

deAtog commented Oct 13, 2020

Please come up with a compelling testing case (or suite) to demonstrate that

  1. Without your code changes, the testing would fail;
  2. With your code changes, the testing would succeed.

This is invaluable both in vallidation and long-term maintaining. Feature PR without testing case would be seen as incomplete work. Please see existing testing cases for example or template.

My apologies, the work here is still a work in progress and based on changes I'm working on in NHibernate. The NHibernate test suite has tests for these changes, but it did not have the failing test in Hibernate. I don't have a build environment for Hibernate ORM so I'm using this pull request to confirm changes. If possible, I will add tests which demonstrate the original cache issue.

@NathanQingyangXu
Copy link
Contributor

NathanQingyangXu commented Oct 14, 2020

Please come up with a compelling testing case (or suite) to demonstrate that

  1. Without your code changes, the testing would fail;
  2. With your code changes, the testing would succeed.

This is invaluable both in vallidation and long-term maintaining. Feature PR without testing case would be seen as incomplete work. Please see existing testing cases for example or template.

My apologies, the work here is still a work in progress and based on changes I'm working on in NHibernate. The NHibernate test suite has tests for these changes, but it did not have the failing test in Hibernate. I don't have a build environment for Hibernate ORM so I'm using this pull request to confirm changes. If possible, I will add tests which demonstrate the original cache issue.

No worries. A good feature of github is the DRAFT PR creation option which makes your progress transparent without the danger to have your PR merged by accident.
Testing case(s) should be mandatory for such PR. It is highly advised to create broken testing case(s) first before changing code.

@deAtog deAtog force-pushed the HHH-14216 branch 10 times, most recently from a919cf8 to 9021f99 Compare October 19, 2020 20:17
Copy link
Member

@sebersole sebersole left a comment

Choose a reason for hiding this comment

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

Overall looks great! Thanks for working on this

One minor request... we like to have newlines at the end of files and quite a few of the files here do not.

Other than that, +1 from me

@deAtog deAtog requested a review from sebersole November 4, 2020 03:30
Copy link
Member

@sebersole sebersole left a comment

Choose a reason for hiding this comment

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

Thanks for adding the line endings. And thanks for the contribution - it looks great

@sebersole sebersole merged commit 1c6e2b4 into hibernate:master Nov 4, 2020
@deAtog deAtog deleted the HHH-14216 branch November 4, 2020 17:42
@cristatus
Copy link
Contributor

This change is breaking the L2 cache behaviour and prevents us to migrate to 5.5.x. I would suggest to fallback to old behaviour if referenced entity is not or can not be cached.

@deAtog
Copy link
Author

deAtog commented Nov 24, 2021

@cristatus I've been using this in production with a L2 cache without issue. Can you provide a test case that demonstrates the problem you are experiencing?

@cristatus
Copy link
Contributor

@deAtog sorry for the late reply but the issue is already fixed upstream #4228. For the reference and test case check https://hibernate.atlassian.net/browse/HHH-14826.

@deAtog
Copy link
Author

deAtog commented Jan 19, 2022

@cristatus I took a look at your test case. While I agree there could be an issue, I'm not sure I agree with the cause. Your test calls ProductConfig.setProduct but not Product.setConfig. As such your in-memory objects at the time of persist are not consistent. As such, the cascade from ProductConfig to Product never occurs and your cache is incorrect. There are two ways to resolve this issue. 1. Either explicitly call Product.setConfig before calling persist() or 2. Modify ProductConfig.setProduct and Product.setConfig to call each other whenever the value changes. The patch you've provided greatly decreases performance as every null value must be verified by a database lookup.

@cristatus
Copy link
Contributor

@deAtog I see. BTW, the code was working fine with earlier versions, so it should be considered as breaking change.

@NathanQingyangXu
Copy link
Contributor

@deAtog , I confirmed a regression issue and created a PR here: #5061 (for https://hibernate.atlassian.net/browse/HHH-15045). Please take a look to confirm my understanding is correct. Thanks.

@raissi
Copy link

raissi commented Sep 18, 2022

Hi,
I think because of adding the dirty check here, we have this issue: https://hibernate.atlassian.net/browse/HHH-15235
In the provided test case (see linked repo https://github.com/MKaciuba/sb267-one-to-one-property-access-exception), the uniqueKeyPropertyName is: "bar" while we are looking for the identifier (must be id), called here with current object of type Foo.
A dirty and fast solution would be to check in line 157 if this.entityName is the same as current and/or old values. Better solutions would be to fix the calling code ?

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

Successfully merging this pull request may close these issues.

5 participants