Let me try to get this right. I have two addresses A1 and A2 in the DB
and a city C1. C1 is associated with A1 and A2 in the DB via foreign
key. My understanding is that all three 'objects' are persisted in the
DB but detached for NH. I now load A1 (in a session) which makes it
attached/persistent for NH. When I try to delete A1 I get into trouble
as A2 is not in the session (still detached). In other words NH is not
aware of the existence of A2 as it is detached. If I would have loaded
A2 as well, NH would be 'clever enough' not to delete C1 as it is
still associated with A2. So it 'stupidly' tries to delete C1 as well.
Is this roughly right?

Not sure what the point of Delete-orphan is then as I would have to
load the whole object graph each time to make NH 'aware' of the
associations.

Best wishes,

Christian


On Oct 1, 3:01 pm, Nexus <[email protected]> wrote:
> Hi,
>
> This only implies on objects loaded in the session !!! Delete-orphan
> deletes orphans as long as they are not referenced by any other object
> in the session
>
> Kind regards
>
> Nexus
>
> On Oct 1, 11:18 am, csetzkorn <[email protected]> wrote:
>
>
>
> > 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 -- 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