Wrong handling of composite primary key with @MapsId

Description

Github project to reproduce: https://github.com/tmonney/hibernate-mapsid

Suppose a pair of entities defined with the same composite primary key:

Parent.java

Child.java

Key.java

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):

Child.java

Environment

None

Assignee

Unassigned

Reporter

Thierry Monney

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

Priority

Major
Configure