orphan removal doesn't work with uni directional onetoone and @mapsId

Description

With the following entities, orphan removal works as expeted when setting parent.setChild(null). However it fails with an "EntityExistsException" when I try and set the child to a new Child object (parent.setChild(new Child());

Environment

mysql

Activity

Show:
Gail Badner
October 26, 2016, 12:26 AM

Possibly related to HHH-11144.

Gail Badner
October 26, 2016, 9:42 PM

Not related to HHH-11144.

Gail Badner
October 27, 2016, 9:21 PM

I believe this is expected. After all, the new entity will ultimately have the same ID as the old (the same as the Parent#id). Hibernate assumes that 2 entities with the same ID represent the same entity. There can only be one representation of the same entity in the PersistenceContext.

rodney ewing
October 28, 2016, 2:35 AM

I'm not sure what the intended behavior is. I'm fairly certain this works in eclipse link, and the jpa spec wasn't too clear about it.

Christopher Smith
September 12, 2018, 5:07 PM

If "Hibernate assumes that 2 entities with the same ID represent the same entity", then Hibernate is making assumptions that contradict the specification. Specifically, when the Java reference on a @MapsId is updated (particularly, set to null), the physical ID field is supposed to track it.

Please see also and HHH-9663.

Assignee

Unassigned

Reporter

rodney ewing

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure