-->
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: How to delete a row from ISet
PostPosted: Sun Mar 25, 2007 4:29 pm 
Newbie

Joined: Tue Mar 06, 2007 4:46 am
Posts: 7
Hello,
I've a problem when I want to delete a row from an ISet.

I removed the row by calling
Code:
originalSet.Remove(item);


But when I call the save-method only UPDATES are made in the database
Code:
        public virtual void Save(dc_tblTest obj)
        {
            using (ISession session = factory.OpenSession())
            {
                ITransaction tx = session.BeginTransaction();
                session.SaveOrUpdate(obj);
                tx.Commit();
            }
        }


Shouldn't NHibernate know that I removed one item from the ISet and automatically delete that row from the database?

In the mapping-file I've specified cascade="all"
Code:
    <set
      name="list_tblAdresse"
      inverse="true"
      cascade="all">

      <key column="ID_Test"/>
      <one-to-many class="BusinessLayer.Interface.dc_tblAdresse, BusinessLayer.Interface"/>
    </set>


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 25, 2007 5:53 pm 
Expert
Expert

Joined: Fri May 13, 2005 5:56 pm
Posts: 308
Location: Santa Barbara, California, USA
inverse=true tells NH that the object is managed from the other side of the association so you you need to remove it from the collection and delete the reference from the other side. As an example:

Code:
Parent p = new Parent();
for (int i = 0; i < 3; i++) {
  Child c = new Child();
  c.Parent = p;
  p.Children.Add(c);
}

dbSession.SaveOrUpdate(p);

....

p.Children.Remove(c);
dbSession.Delete(c);

remember that c is in memory and carries a reference to p so simply removing c from the p.Children collection does nothing when NH comes around to find c in memory with a reference to p.

hth,

-devon


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.