-->
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.  [ 1 post ] 
Author Message
 Post subject: Filters and One-Shot Delete - Suggestions?
PostPosted: Sun Jul 27, 2008 8:05 pm 
Newbie

Joined: Sun Oct 22, 2006 11:28 am
Posts: 15
Hi All,

I have a collection of composite elements that I'm using a filter on so that my HQL query only returns the single element I'm interested in, based on a users location.

In certain conditions, I remove this element from the collection and force an update.

Since the collection is now empty ( it isn't really, there are many other entries in the link table for other locations ), hibernate is performing a one-shot delete and removing everything from the table.

Is there a way to force it to just delete the one I removed from the collection?

Here is the relevant stuff:

The Mapping:

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

         <collection-id type="integer" column = "id">
            <generator class="increment"/>
         </collection-id>
         
          <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" />
      </idbag>


The query that is filtered:

Code:
   <query name="find.store.task.occurrence.by.id" >
      select distinct occ from TaskOccurrence occ
         left join fetch occ.completions
         left join fetch occ.locationsStatus
         left join fetch occ.readByLocations
         left join fetch occ.readByUsers
         where occ.id = :task
   </query>


Without filtering the collection, the result set return can be huge because of the cartesian joins! The occurence contains the 'completion' collection referenced above.

I know I can manually write HQL to do this, but it would be nice to avoid doing that.

This is an urgent matter, any help is greatly appreciated.
Cheers,
Ian
[/code]


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

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.