-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Conversation
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. |
Please come up with a compelling testing case (or suite) to demonstrate that
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. |
a919cf8
to
9021f99
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.
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
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.
Thanks for adding the line endings. And thanks for the contribution - it looks great
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. |
@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? |
@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. |
@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. |
@deAtog I see. BTW, the code was working fine with earlier versions, so it should be considered as breaking change. |
@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. |
Hi, |
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.