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]