-->
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: Hibernate Filtered collection and delete-orphan cascading
PostPosted: Thu Jul 24, 2008 9:45 am 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.3.0ga

Name and version of the database you are using:
mySQL 5.0.27

Hi,

I have a parent object with a set of <composite-element> children, with cascade="all, delete-orphan"

I have a filter on the collection that limits the collection to items based on the current user and their location, so the collection only has 1 element most of the time.

When I remove this element from the collection and save to the db, Hibernate removes all items from the db, probably because the collection is now empty. It does a delete from ... where id = ...

This ends up deleting records for other users and locations.

What is the recommended way to handle this?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 5:11 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
Nobody has run into this? It would seem odd that I have to load the entire collection just to delete a single entry.....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 24, 2008 6:07 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
A bit more info - here is the collection mapping:

Code:
      <set name="completions"
          lazy="true"
          table="task_completion"
          cascade="all, delete-orphan" >

          <key column="task_occurence_id" />

          <composite-element class="com.opterus.opscenter.model.task.TaskCompletion" >
             <property name="date" column="date" not-null="true" />
             <many-to-one name="location" class="com.opterus.opscenter.model.common.Location" column="location_id" not-null="true" unique="false" />
             <many-to-one name="user" class="com.opterus.opscenter.model.common.User" column="user_id" not-null="true" unique="false" />
             <property name="verificationDate" column="verification_date" not-null="false" />
             <many-to-one name="verificationUser" class="com.opterus.opscenter.model.common.User" column="verification_user_id" not-null="false" unique="false" />
         </composite-element>
         
         <filter name="locationFilter" condition="location_id = :locationId" />
      </set>


I suspect the problem is because the key is specified as task_occurence_id, but what I really need is to have location_id and user_id involved in the delete statement.

Is there a way to do that, do I have to use a composite key?

The table has those 3 fields make up the primary key.

Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 27, 2008 3:40 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
Anybody??


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.