Skip to content

HHH-15045 + HHH-15235 #5330

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
Sep 23, 2022
Merged

HHH-15045 + HHH-15235 #5330

merged 4 commits into from
Sep 23, 2022

Conversation

dreab8
Copy link
Member

@dreab8 dreab8 commented Sep 22, 2022

…netoOne relationship when no table columns are changed - PropertyAccessException on merging Bidirectional OneToOne with EmbeddedId - Reverted HHH-14216
@dreab8 dreab8 force-pushed the HHH-15045_HHH-15235 branch from 34a8f06 to 2600258 Compare September 22, 2022 12:05
@dreab8 dreab8 merged commit f935eb2 into hibernate:main Sep 23, 2022
@deAtog
Copy link

deAtog commented Oct 19, 2022

I'm fairly certain that the issue here can be solved by correcting the versioning of the one-to-one relationships. Right now, all one-to-one relationships are versioned. This does not make sense to me as I do not see why you would version a property that is not stored in the database. The fact that a flush occurs was in my opinion correct. Consider a simple case where you load the parent and add a child. The state of the parent is modified and a flush to the underlying cache is required, but a database update is not. The existing code currently breaks because the one-to-one relationship from the parent to the child in this case is versioned. This causes the version of the parent to be incremented when the child is added to the parent. I think overriding the isOptimisticLocked method of the OneToOne type to return true only when the value is to be stored in the database would correct this issue.

The OneToOne documentation provides the following examples for defining one-to-one relationships:

  1. One-to-one association that maps a foreign key column.
    • This uses a OneToOne from the parent to the child and a ManyToOne from the child to the parent.
  2. One-to-one association that assumes both the source and target share the same primary key values.
    • This uses a OneToOne from the parent and a OneToOne from the child to the parent with constrained set to true.
  3. One-to-one association from an embeddable class to another entity.
    • This uses a ManyToOne from the parent to the child and a OneToOne from the child to the parent? (inferred from reading the code only).

In the above cases, the only time the OneToOne should be versioned is when the OneToOne is constrained in the second case. Therefore, the fix here may be to only return true from OneToOne.isOptimisticLocked() when OneToOne.isConstrained() returns true.

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.

3 participants