-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to remove entries in an array through saveOrUpdate
PostPosted: Thu Sep 29, 2005 10:38 am 
Newbie

Joined: Tue Aug 23, 2005 10:02 am
Posts: 7
I think this should be an easy question/answer, but I've been wrong before. I've defined a class that has a one-to-many relationship to another class, and I want the data from the one-to-many table to be returned as an array. Here's the definition of the parent class:

<class name="com.ibm.caes.wcs.db.cache.beans.UserPreferences" table="user">
<cache usage="read-write"/>
<id name="webId" column="webId"/>
<array name="searches" inverse="true" cascade="all, delete-orphan">
<cache usage="read-write"/>
<key column="userid" not-null="true"/>
<list-index column="index"/>
<one-to-many class="com.ibm.caes.wcs.db.cache.beans.SavedSearch"/>
</array>
</class>

Here's the definition of the one-to-many class, the data of which I want to be returned as an array:

<class name="com.ibm.caes.wcs.db.cache.beans.SavedSearch" table="iphrasesavedsearches">
<cache usage="read-write"/>
<composite-id>
<key-property name="userId"/>
<key-property name="index"/>
</composite-id>
<property name="ipState"/>
<property name="queryId"/>
<property name="rank"/>
<property name="name" column="pspname"/>
</class>

I update the userPreferences object using the saveOrUpdate() method. If I add elements to the array, the new elements are persisted just fine. If I rearrange the order of the elements in the array by modifying the index field, again the changes are persisted just fine. But, if I remove an element from the array, the removed element isn't deleted from the table when the saveOrUpdate() method is called. I don't seem to have this problem with other types of collections (such as a set).


Top
 Profile  
 
 Post subject: syntax
PostPosted: Thu Sep 29, 2005 10:53 am 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Quote:
<array name="searches" inverse="true" cascade="all, delete-orphan">


Shouldnt' it be
<array name="searches" inverse="true" cascade="all-delete-orphan"> ?

per http://www.hibernate.org/hib_docs/v3/re ... tions.html

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject: syntax change didn't fix the problem.
PostPosted: Thu Sep 29, 2005 4:10 pm 
Newbie

Joined: Tue Aug 23, 2005 10:02 am
Posts: 7
Nope, changing it from "all, delete-orphan" to "all-delete-orphan" didn't fix the problem. Also, the documentation shows both forms, so I don't know if they behave differently or not. But regardless, I still can't seem to get rid of deleted elements in an array from the corresponding database table.


Top
 Profile  
 
 Post subject: you are correct
PostPosted: Thu Sep 29, 2005 4:47 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Yes, by some reasons delete orphaned does not work with arrays.
Code:
<array name="addresses" table="ent_address_arr" cascade="all-delete-orphan"  >
      <key column="ent_id"/>
      <index column="ind"/>

      <many-to-many column="address_id" class="Address"/>
    </array>


does not cause unreferenced Address to be deleted

Code:
    <list name="addresses" table="ent_address_arr" cascade="all-delete-orphan"  >
      <key column="ent_id"/>
      <index column="ind" />
      <many-to-many column="address_id" class="Address"/>
    </list>


deletes unreferenced record from address.

I suggest submitting bug .
[/code]

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.