-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cascading a delete for all objects
PostPosted: Sun Oct 23, 2005 12:25 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I've a very strange problem. NHibernate is capable of deleting a single item, but it refuse to delete them all.
I'm getting a "NHibernate.ObjectDeletedException : deleted object would be re-saved by cascade (remove deleted object from associations): 18, of class: Model.Assignment" error when it happens.

I'm doing something like:

session.Delete("from Assignment");

And it fails.

Trying to do delete a single item.
I can't figure out why this is happening!

The mapping is here:

Code:
<hibernate-mapping xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="urn:nhibernate-mapping-2.0">
  <class name=".Model.FixedWorkPlanAssignment, .Model" table="FixedWorkPlanAssignments"    >
    <id name="Id" access="nosetter.camelcase-underscore" column="WorkPlanAssignmentId" type="Int32"  unsaved-value="0">
      <generator class="native">
      </generator>
    </id>
    <property name="_occupationId" access="field" column="OccupationId" type="Int32"        />
    <property name="AssignmentDays" access="property" column="AssignmentDays"         />
    <property name="CycleType" access="property" column="CycleType"         />
    <many-to-one name="BoardTemplate" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" class=".Model.BoardTemplate, .Model" column="BoardTemplateId"      />
    <many-to-one name="FixedWorkPlan" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" class=".Model.FixedWorkPlan, .Model" column="WorkPlanId"      />
    <many-to-one name="ShiftTemplate" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" class=".Model.ShiftTemplate, .Model" column="ShiftTemplateId"      />
    <many-to-one name="TaskTemplate" access="NHibernate.Generics.GenericAccessor, NHibernate.Generics" class=".Model.TaskTemplate, .Model" column="TaskTemplateId"      />
  </class>
</hibernate-mapping>


Here is what fails:

Code:
session.Delete("from Model.Assignment");
session.Flush();


[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 12:42 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
I should mention that assignment is references by several objects, (it's the child most object), and those references' cascades are all-delete-orphans


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 12:44 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Okay, I changed them all to cascade = "none" and it's working, but it's not what I wanted.
I want it to delete all assignments if I delete the employee schedule.

How do I get both of them?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Oct 23, 2005 12:46 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Looks like it's the day where I keep replying to myself :-)

Anyway, another request, is it possible to add the parent of the referencing collection, so I wouldn't have to debug NHibernate to figure out where the problem is?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 10:30 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
I'm here now :)

I hardly understand your problem... In the mapping you posted, the "Assignment" is called FixedWorkPlanAssignment and the mapping of the employee schedule is missing...

For your last request, you can create a JIRA issue ;)

OT: What's the purpose of the "." before classes names? (eg: ".Model.FixedWorkPlan")?

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 10:40 am 
Beginner
Beginner

Joined: Tue May 17, 2005 11:42 am
Posts: 22
Maybe you are having the same problem as me.
http://nhibernate.sourceforge.net/forum ... .php?t=749


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