Session.saveOrUpdateCopy(object) overwrites input object parameter for classes with embedded composite id

Description

Session.saveOrUpdateCopy(object) overwrites the parameter object if the mapping for its class defines an embedded composite-id (key not stored in a separate object, but is the object itself).

I have debugged inside hibernate code and notice that saveOrUpdateCopy() retrieved first the obejct from the database (so far ok). To retrieve the object from the db, hibernate gets frist the object identifier. Since the mapping for this table is defined with an embedded composite, the metdor ClassPersister.getIdentifier(object) returns the same object reference. the problem seems to be in SessionImpl.doCopy() line 04083:
result = get(clazz, id);
This method overwrites the contest of if, which is a reference to object , thereofre the input parameter is overwritten.

The bug does not happens with simple ids, or composite-ids defined in a separate Id class.

A workaround for the bug is to use instead the method session.saveOrUpdateCopy(aObject, id2), by getting the objet identifier and duplicating it (I did it with serialization which is slow) to another object (id2) so that id2 is overwrriten but the original object not.

Environment

JDK "1.4.2_08". Windows XP Home. jTDS-1.1.jar

Assignee

Unassigned

Reporter

Pepe Perez

Labels

None

Feedback Requested

None

Feedback Requested By

None

backPortable

None

Suitable for new contributors

None

Pull Request

None

backportDecision

None

backportReEvaluate

None

Affects versions

Priority

Major
Configure