Cascaded merge of a Many-to-many link entity generates invalid INSERT

Description

I was trying to do a Many-to-many setup with a link entity (as described in the manual).

Using the entities from the manual, when I call Session.merge after assigning an Address to a Person, Hibernate attempts to insert a (null, null) tuple into the link table. The problem only affects mergepersist seems to work fine.

I've stepped through it with a debugger and it seems, that SessionImpl.instantiate (called during the cascading merge) does not copy over the two @Id fields.

I've reproduced it with 5.2.2, 5.2.1 and 5.0.9, with both PostgreSQL and H2. Both databases won't insert the null values into the primary key, of course.

A test case is attached.

Environment

Linux, PostgreSQL 9.5.3, H2 1.3.176

Assignee

Unassigned

Reporter

Henning Hoefer

Fix versions

None

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure