Non-Cascaded relations are replaced during merge

Description

After upgrading from Hibernate 3.6.5 to 4.2.5, we discovered the following change in behaviour of EntityManager.merge:

Assume you assemble a parent entity p with an ID, and have a non-cascaded collection childCollection of child entities C-1 .. C-n attached, with or without IDs.

Then calls to EntityManager.merge(p) lead to the following in the returned instance:

  • the collection of child entities is now a persistent collection

  • the persistent collection has exactly the same number of entries as the original collection

  • child entries with an ID have been replaced with instances resolved from the session

  • child entries without an ID have been replaced with new instances containing all null values (i.e. only the default constructor has been called)

With Hibernate 3.6.5.Final, the child collection and all of its entries remained completely untouched.

I'm not sure what exactly the desired behaviour is, but I guess the current one is not exactly what you had in mind, right?

Environment

None

Assignee

Unassigned

Reporter

Andreas Gudian

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