-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Hibernate not insert re-attached collection? (bug?)
PostPosted: Wed Jan 26, 2011 4:50 pm 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
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?


Top
 Profile  
 
 Post subject: Re: Hibernate not insert re-attached collection? (bug?)
PostPosted: Fri Jan 28, 2011 6:55 am 
Regular
Regular

Joined: Thu Aug 28, 2003 2:42 pm
Posts: 77
Location: The Netherlands
Anybody any idea?
Is this a bug? Should I post it as such?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.