version: 3.6.0.final
I have the following situation:
An entity with a collection, containing value type objects, with cascading fully enabled.
1) I remove, the collection and store it to the db. Then load it to check that the collection indeed is removed.
2) I then add the removed collection and store the entity again. Then I load it again to check the result and notice that the collection is empty, which it shouldn't :(...
What am I doing wrong or is this a bug?
When I use a clean created collection in 2), that doesn't exists of Hibernate objects, it works fine.., that is: the collection is correctly stored in the db.
In code, my mapping:
Code:
<class name="com.sample.Declaration" table="decl">
<id name="id" column="id" type="string" length="40" access="property">
<generator class="assigned" />
</id>
<set name="statusHistory" table="decl_sts_hist" lazy="false" cascade="all">
<cache usage="read-write" />
<key column="idDec" not-null="true" />
<composite-element class="com.sample.DeclarationStatusDefault">
<property name="remark" column="remark" type="string" length="254" />
<property name="statusName" column="stsName" type="declarationStatusName" not-null="true" update="false" />
</composite-element>
</set>
</class>
The code:
Code:
// 1): clear the status history
Declaration dec = Persister.findDeclarationById("id");
SortedSet<DeclarationStatus> history = dec.getStatusHistory();
dec.setStatusHistory(null);
dec.saveOrUpdate(); // will call saveOrUpdate on the current session.
Declaration dec = Persister.findDeclarationById("id");
assertNull(dec.getStatusHistory()); // OK
// 2) recover the status history
dec.setStatusHistory(history);
dec.saveOrUpdate(); // will call saveOrUpdate on the current session.
Declaration dec = Persister.findDeclarationById("id");
assertNull(dec.getStatusHistory()); // ERROR, is empty like before
If I create a new Set with a few entries and store it, it all works fine, but when I store the old history that contains Hibernate objects, like the PersistSet, it will NOT be stored in the db...
Stranggeee.... Is this expected behavior?... I more smell like a bug or I am missing something here...
If I debug the Hibernate code, the collection entries are never marked as updated/recreated in the method Collections.prepareCollectionForUpdate() because the loadedPersister and currentPersister are the same for some reason...
Anybody any idea?