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

OneToOneWithoutMapsIdEvent is not applicable when parent and child are the same class/table #243

Open
pkernevez opened this issue May 28, 2024 · 1 comment
Labels
requires investigation Needs more research

Comments

@pkernevez
Copy link

pkernevez commented May 28, 2024

Hi I have chains with MovementEntities with a OneToOne relation.

public class MovementEntity {
...
    @OneToOne(optional = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_MOVEMENT_ID")
    private MovementEntity parentClientSecurityMovement;

The optimizer show me this error:
Hypersistence Optimizer : CRITICAL - OneToOneWithoutMapsIdEvent - The [parentClientSecurityMovement] one-to-one association in the [tech.lightframe.shift.cbs.operation.MovementEntity] entity is using a separate Foreign Key to reference the parent record. Consider using @MapsId so that the identifier is shared with the parent row. For more info about this event, check out this User Guide link - https://vladmihalcea.com/hypersistence-optimizer/docs/user-guide/#OneToOneWithoutMapsIdEvent

But this strategy is not applicable when parent and child are in the same table. They are different instances and can't have the same Id.
I think the optimizer should filter these cases.

@vladmihalcea
Copy link
Owner

From JPA perdpective, that's a @ManyToOne association. If you replace it with @ManyToOne, it will work just fine.

@vladmihalcea vladmihalcea added the requires investigation Needs more research label Jun 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires investigation Needs more research
Projects
None yet
Development

No branches or pull requests

2 participants