Hello Fabio.
Yes, that is correct. A has a set property for holding several Bs and each B
has a property that points back to its parent A. The problem is that
deleting A won't cascade into B and I get an foreign key exception when I
try to delete A. The workaround I've found is deleting all Bs before
deleting A but I expected that deleting A would automatically delete all
associated Bs . If you want, I can put some code here (I thought that the
previous snippet was enough for illustrating my scenario).
Thanks.
--
Luis Abreu
From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf
Of Fabio Maulo
Sent: segunda-feira, 29 de Setembro de 2008 16:59
To: [email protected]
Subject: [nhusers] Re: delete and cascading
I don't understand the relation..
A has a One-To-Many to B (OK)
B has a ONE-TO-ONE with A ?
What is this?
2008/9/29 Luis Abreu <[EMAIL PROTECTED]>
Hello guys.
question regarding NH 2.0 behaviour:
I've got an entity with a collection of other entities. It looks like
this (just some pseudo-code that reproduces the scenario):
class A{ public ISet<B> Bs{get;set;} }
class B{ public A{ get; set; } }
and then the xml looks like this:
a.hbm.xml
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
assembly="SRA.Core.Entidades"
namespace="SRA.Core.Entidades"
schema="dbo">
<class name="A" table="A" lazy="false">
...
<set name="Bs" lazy="false" cascade="all-delete-orphan" inverse="true">
<key column="IdB" on-delete="cascade" />
<one-to-many class="B"/>
</set>
</hibernate-mapping>
b.hbm.xml
<hibernate-mapping
xmlns="urn:nhibernate-mapping-2.2"
assembly="SRA.Core.Entidades"
namespace="SRA.Core.Entidades"
schema="dbo">
<class name="B" table="B" lazy="false">
...
<one-to-one class="A" name="A" />
</hibernate-mapping>
As you can see, A is the root aggregate and I won't to delete A. So I
tried calling session.Delete(a). The problem: I end up getting an ado
net exception regarding the foreign key between tables A and B. Ok,
looking at the SQL, it seems like NH will only issue a delete over
table A, but I was expecting that the cascade all would also issue a
delete over B (which should be issued before A's delete).
Shouldn't the delete over A be responsible for deleting items from B
associated with A?
--
Regards,
Luis Abreu
--
Fabio Maulo
No virus found in this incoming message.
Checked by AVG - http://www.avg.com
Version: 8.0.169 / Virus Database: 270.7.0/1685 - Release Date: 27-09-2008
13:11
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---