-->
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.  [ 2 posts ] 
Author Message
 Post subject: Deleting a parent class
PostPosted: Mon Nov 07, 2005 12:22 pm 
I have a Project class that has a bag of Release classes, representing a one-to-many relationship. When attempting to perform a Delete operation on the Project class I get the following error:

SQL insert, update or delete failed (expected affected row count: 1, actual affected row count: 5). Possible causes: the row was modified or deleted by another user, or a trigger is reporting misleading row count.

I have cascade deletes enabled in SQL Server for the tables
Here is the code I am attempting to use:

Project existingProject;
try
{
using (Repository r = new Repository())
{
r.Open();
r.BeginTransaction();
existingProject = (Project)r.Get(typeof(Project), 1);
// 1 is a valid Project ID
r.CommitTransaction();
}
using (Repository r = new Repository())
{
r.Open();
r.BeginTransaction();
r.Delete(existingProject);
r.CommitTransaction();
}
}
catch
{
throw;
}

And my mappings:

<!-- generated using NHibernate.hbm.cst, see http://www.intesoft.net/nhibernate for notes and latest version -->
<class name="Scorecard.Entities.Project, Scorecard.Entities" table="tblProject">
<id name="ID" type="Int32" unsaved-value="0">
<column name="ProjectID" sql-type="int" not-null="true" unique="true" index="PK_tblProject"/>
<generator class="native" />
</id>
<property name="Name" type="String">
<column name="Name" length="50" sql-type="varchar" not-null="true"/>
</property>
<property name="SummaryID" type="Int32">
<column name="SummaryID" sql-type="int" not-null="true"/>
</property>
<bag name="Releases" inverse="true" lazy="false" cascade="all">
<key column="ProjectID"/>
<one-to-many class="Cintas.Scorecard.Entities.Release, Cintas.Scorecard.Entities"/>
</bag>
<bag name="ProjectMetrics" inverse="true" lazy="false" cascade="all">
<key column="ProjectID"/>
<one-to-many class="Cintas.Scorecard.Entities.ProjectMetric, Cintas.Scorecard.Entities"/>
</bag>
</class>
</hibernate-mapping>


Any help would be much appreciated


Top
  
 
 Post subject:
PostPosted: Mon Nov 07, 2005 8:32 pm 
Regular
Regular

Joined: Thu May 12, 2005 10:12 am
Posts: 71
Location: Buenos Aires, Argentina
I believe the problem is related to the cascading trigger you mention. Is there a posibility to disable the trigger in the DB or is it necesary?

Remember that NH can take care of cascading delete. In fact you told him to cascade delete in the following line:

<bag name="Releases" inverse="true" lazy="false" cascade="all">

and that is probably the source of your problem, since the DB is cascading a delete (with triggers) and afterword NH tries to do the same isuing delete statements because of the cascade="all" directive.


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