Github project to reproduce: https://github.com/tmonney/hibernate-mapsid
Suppose a pair of entities defined with the same composite primary key:
The bug manifests itself when loading a Parent entity, getting its child, modifying some of its fields and finally flushing the entity manager:
This is because Hibernates executes the following query:
And passes the same value for id1 and id2, which is obviously wrong.
Interestingly enough, everything works OK if the mapping of the Child class is changed as follows (notice the second join column of the parent is renamed):