The modification of a @OneToOne with @MapsId property is silently ignored during a merge operation

Description

Creating issue for discussion here at https://discourse.hibernate.org/t/hibernate-onetoone-with-mapsid-does-not-map-the-same-id-with-the-parent-entity/2093/9

Summary:
A child entity is mapped using @OneToOne with @MapsId to its parent entity.

For eg,

The assumption is that child will refer to its correct parent in any case. However, following code will break this assumption.

This way it will continue to use new parent until the end of transaction.

@OneToOne with @MapsId should always resolves to correct association value.

Sample test cases which show the issue.
https://github.com/pmverma/hibernate-mapsid-test
https://github.com/vladmihalcea/high-performance-java-persistence/pull/36

Environment

Hibernate Version: 5.2.17
java version "1.8.0_181"
Java(TM) SE Runtime Environment (build 1.8.0_181-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
Windows 10
Postgresql 10.4

Status

Assignee

Vlad Mihalcea

Reporter

P. Mohan

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure