Hi,

Sure that makes sense. However, I thought that NHibernate takes care
of this (implements transparent persistence) as I use:

delete-orphan

My understanding of this is that the persistence manager is clever
enough to leave the city 'alone' if another 'object' is associated
with it (i.e. does not attempt to delete - only if it is the 'last
city').

Thanks.

Christian

On Sep 30, 2:15 pm, Lionel Orellana <[email protected]> wrote:
> The error message doesn't say that the city was not found.
>
> You are trying to delete a City that is referenced by another Address.
> It's the foreign key constraint that's kicking in.
>
> Lionel.
>
> On Sep 29, 6:08 am,csetzkorn<[email protected]> wrote:
>
>
>
> > Sorry. The exact exception is:
>
> > {"could not delete: [Bla.Domain.City#3][SQL: DELETE FROM Cities WHERE
> > CityId = ?]"}
>
> > Is there something wrong with the mapping file? I tend to keep it in
> > one file. Seems to work fine.
>
> > C
>
> > On Sep 28, 8:41 pm, Fabio Maulo <[email protected]> wrote:
>
> > > You are writing too much in the mapping...
> > > btw"city cannot be found although  it definitely exist."
> > > is not an NH's exception message.
>
> > > 2009/9/28csetzkorn<[email protected]>
>
> > > > Hi,
>
> > > > Thanks I noticed the typo myself. Now it seems to work for the last
> > > > object that has a reference to the city (here it is ok to delete the
> > > > ‘last city’) but not for any objects ‘before’. I get an exception that
> > > > the city cannot be found although  it definitely exist.
>
> > > > Here are some fractions of my mapping file:
>
> > > > ...
> > > > <joined-subclass
> > > >      name="Address" table="Addresses" dynamic-update="true">
> > > >      <key foreign-key="ItemIdAddress" column="AddressId"></key>
> > > > ...
> > > > <many-to-one name="City" class="City" column="CityId" cascade="delete-
> > > > orphan"  />
> > > > ...
> > > > </joined-subclass>
> > > > ...
> > > > <class name="City" table="Cities">
>
> > > >    <id name="CityId" unsaved-value="0">
> > > >      <column name="CityId" sql-type="bigint"/>
> > > >      <generator class="identity" />
> > > >    </id>
>
> > > >    <property name="CityName" >
> > > >      <column name="CityName" not-null="true" sql-type="char(100)"/>
> > > >    </property>
>
> > > >  </class>
>
> > > > I am using generic DAOs for all my classes. This is the code for
> > > > deletion:
>
> > > > ...
> > > > public void MakeTransient(T entity)
> > > >        {
> > > >            Session.Delete(entity);
> > > >            Session.Flush();
> > > >        }
> > > > ...
>
> > > > Looking forward to hearing from you.
>
> > > > BTW is there a good book/paper/etc. with examples of more complicated
> > > > scenarios of modelling and implementing different relationships plus
> > > > DAO code exacmples. I have NHibernate in Action which only seems to
> > > > touch the surface.
>
> > > > Thanks.
>
> > > > Christian
>
> > > > On Sep 28, 4:41 pm, Fabio Maulo <[email protected]> wrote:
> > > > > It is only a TYPO : It is "delete-orphan" and not "delete-orphans"
>
> > > > > 2009/9/28csetzkorn<[email protected]>
>
> > > > > > Hi,
>
> > > > > > Can I use:
>
> > > > > > <many-to-one name="City" class="City" column="CityId" 
> > > > > > cascade="delete-
> > > > > > orphans"  />
>
> > > > > > I get:
>
> > > > > > Unsupported cascade style: delete-orphans
>
> > > > > > although it says here (or not?):
>
> > > > > >http://groups.google.com/group/fluent-nhibernate/browse_thread/thread.
> > > > ..
>
> > > > > > That I can use it.
>
> > > > > > Thanks.
>
> > > > > > Christian
>
> > > > > --
> > > > > Fabio Maulo- Hide quoted text -
>
> > > > > - Show quoted text -
>
> > > --
> > > Fabio Maulo- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to