Don't know about 2, but I'm pretty sure with 1 you either live with it or make it bidirectional.
On Mon, Mar 9, 2009 at 2:39 PM, Mario Hallmann < [email protected]> wrote: > > Hi, > > from an extracted sample application i get the following sql output > which is not as i would like it to be: > > 1. session: > > NHibernate: INSERT INTO [MyAssociatedObject] DEFAULT VALUES; select > SCOPE_IDENTITY() > NHibernate: INSERT INTO [MyObject] DEFAULT VALUES; select > SCOPE_IDENTITY() > NHibernate: INSERT INTO [MyAssociation] (Reference_id) VALUES (@p0); > select SCOPE_IDENTITY(); @p0 = '1' > NHibernate: UPDATE [MyAssociation] SET MyObject_id = @p0 WHERE Id = > @p1; @p0 = '1', @p1 = '1' > > ------------------------------------ > 2. session: > > NHibernate: SELECT myassociat0_.Id as Id2_0_ FROM [MyAssociatedObject] > myassociat0_ WHERE myassociat0_....@p0; @p0 = '1' > NHibernate: SELECT myobject0_.Id as Id0_0_ FROM [MyObject] myobject0_ > WHERE myobject0_....@p0; @p0 = '1' > NHibernate: SELECT mylist0_.MyObject_id as MyObject3_1_, mylist0_.Id > as Id1_, mylist0_.Id as Id1_0_, mylist0_.Reference_id as > Reference2_1_0_ FROM [MyAssociation] mylist0_ WHERE > mylist0_.myobject_...@p0; @p0 = '1' > NHibernate: UPDATE [MyAssociation] SET Reference_id = @p0 WHERE Id = > @p1; @p0 = '', @p1 = '1' > NHibernate: UPDATE [MyAssociation] SET MyObject_id = null WHERE > MyObject_id = @p0; @p0 = '1' > NHibernate: DELETE FROM [MyAssociatedObject] WHERE Id = @p0; @p0 = '1' > NHibernate: DELETE FROM [MyAssociation] WHERE Id = @p0; @p0 = '1' > > > 1. Is there any chance to get rid of the update in the first block > without having a bi-directional association? > 2. The two update statements in the second block are pretty much > useless if the object gets deleted anyway, but I was not able to find > any way around it. > > Is there something wrong with my mappings or is this behaviour by > design? > > > > corresponding mappings and code samples: > > <class name="MyObject" table="`MyObject`" xmlns="urn:nhibernate- > mapping-2.2"> > <id name="Id" column="Id" type="Int32"> > <generator class="identity" /> > </id> > <bag name="MyList" cascade="all-delete-orphan"> > <key column="MyObject_id" /> > <one-to-many class="MyAssociation" /> > </bag> > </class> > > <class name="MyAssociatedObject" table="`MyAssociatedObject`" > xmlns="urn:nhibernate-mapping-2.2"> > <id name="Id" column="Id" type="Int32"> > <generator class="identity" /> > </id> > </class> > > <class name="MyAssociation" table="`MyAssociation`" > xmlns="urn:nhibernate-mapping-2.2"> > <id name="Id" column="Id" type="Int32"> > <generator class="identity" /> > </id> > <many-to-one cascade="none" name="Reference" > column="Reference_id" /> > </class> > > > var session=sf.OpenSession(); > > var myAssociated = new MyAssociatedObject(); > var myAssociation = new MyAssociation() {Reference = myAssociated}; > var myObject = new MyObject(); > myObject.MyList.Add(myAssociation); > > session.Save(myAssociated); > session.Save(myObject); > session.Flush(); > session.Close(); > > Console.WriteLine("------------------------------------"); > session = sf.OpenSession(); > var loadedAssociated = session.Get<MyAssociatedObject> > (myAssociated.Id); > var loadedObject=session.Get<MyObject>(myObject.Id); > > loadedObject.MyList.RemoveAt(0); > session.Delete(loadedAssociated); > session.Flush(); > session.Close(); > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
