-->
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.  [ 15 posts ] 
Author Message
 Post subject: Delete not executing
PostPosted: Mon Jun 01, 2009 5:39 pm 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
Hi,

I have something very strange going on but since i am pretty far from the "standard" Nhibernate situation, i am not 100% sure i am doing it right :s

There is a table Media
a table Selectionlist
and then a table selectionlist_mediamembers (where 1 selectionlist and 1 media can be on a row)

Now i do use logical deletes ( update table set deleted = 1 where id = ?)

There is also a global interceptor that checks certain actions on entities and sends out MessageQueue messages accordingly.

Now when i do a delete of one of these mediamembers, I first remove it from all collections, and then do the actualy delete:

Code:
if (MessageBox.Show("Are you sure you want to remove this media from the selectionlist: "+Environment.NewLine+Environment.NewLine+oSelectionlist.Media.Author.Name + " - " + oSelectionlist.Media.Title, "WARNING: Are you sure ?", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                try
                {
                   
                    oSelectionlist.Media.SelectionlistMediamembers.Remove(oSelectionlist);
                   
                    oSelectionlist.Selectionlist.SelectionlistMediamembers.Remove(oSelectionlist);
                   
                  //  MessageBox.Show("Going to remove: " + oSelectionlist.Media.Title + " - " + oSelectionlist.Media.Author.Name);
                    MessageBox.Show ("Before Delete");
                    oSelectionMediaManager.Delete(oSelectionlist);
                   
                   
                   
                    //oSelectionMediaManager.Session.CommitChanges();
                   
                   
                    dgvResult.Rows.Remove(dgvResult.SelectedRows[0]);
                }
                catch (Exception ex)
                {
                   
                    throw;
                }
               
            }



Now the weird thing is: sometimes it does the delete, sometimes it does not.. however.. the correct MessageQueue Message is always sent (even when the delete fails...)

Now i have been debugging for more then 8 hours straight and i cannot get nor nhibernate, nor my own app, to generate a single error anywhere... And i am out of ideas..

My custom SQL query for delete seems to be ok since sometimes it does work
Nhibernate returns no error on the delete;
Interceptor returns no error when sending the MQ message
MySql returns no error

But the delete just does not happen .. any ideas ?


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Mon Jun 01, 2009 6:24 pm 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
Ok.. so it get's weirder. I have tested using only .Remove from the Media.SelectionlistMediaMembers collection and then doing a session.commit();

The first one succeeds (although i get FIRST a delete message through the IInterceptor, and then another update, even when the delete has already been done ?)

When i do a second delete, it does a delete, then an update on that "undoes" that delete and an update on the first record i tryed to delete (undoing this delete aswell).. I am stomped at what i am doing wrong ..


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Wed Jun 03, 2009 5:32 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
You have also have to set oSelectionlist.Media = null. If it's still not working try it without the custom delete first.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Thu Jun 04, 2009 5:27 am 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
Hi,

Ok, so i could not test this yesterday because i was not at the office, but i have today and unfortunately.. it keeps giving me this funny effect:

setting oSelectionlist.media = null; IS done in the database, but it still resets the deleted flag to 0 instead of 1

So some different tests with different results:

Standard record delete (not logical) WITHOUT interceptor setting the recdeleted = DateTime.Now() OnDelete action:
works fine, record gets deleted, Interceptor only fires the OnDelete (thus only 1 mq message is sent stating the record was deleted)

Logical delete (without OnDelete setting the recdeleted = DateTime.now():

Mapping file:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TP2.mediabutler.Data.BusinessObjects" assembly="MyApp.Data">
   <class name="MyApp.BusinessObjects.SelectionlistMediamember, MyApp.Data" table="selectionlist_mediamembers" where="deleted = 0" lazy="true">
      <id name="Id" column="id">
          <generator class="assigned" />
      </id>
      <property name="Reccreated" column="reccreated" />
      <property name="Reccreater" column="reccreater" />
      <property name="Recmodified" column="recmodified" />
      <property name="Recmodifier" column="recmodifier" />
      <property name="Recdeleted" column="recdeleted" />
      <property name="Recdeleter" column="recdeleter" />
      <property name="Deleted" column="deleted" />
      <many-to-one name="Selectionlist" column="selectionlist" class="Selectionlist"/>
      <many-to-one name="Media" column="media" class="Media"/>
      <sql-delete>update selectionlist_mediamembers set deleted = 1 where id = ?</sql-delete>
   </class>
</hibernate-mapping>


using code:

Code:
oMedia.SelectionMediaMembers.remove(oSelectionlistToRemove);
oSelectionlistToRemove.media = null;
tx.commit();


Result: First delete works just fine (only OnDelete is fired in Iinterceptor)
When deleting a second record:

The first record i deleted get's updated and deleted flag is reset to 0,
Then the second record get's deleted
then the first record get's updated AGAIN. (no idea what it does here..)

But wait.. it get's better ;-)

Logical Delete with IInterceptor Setting the recdeleted date:

First delete:
OnDelete fires setting recdeleted right and deleted flag to 0 BUT.. does not set media to null ( maybe the order of my code should be reverse ? First set oSelectionlist.Media = null, before kicking it out of the media collection ?

Then, OnUpdate fires, not really doing anything (i think -> don't see changed in the database)


Then on the second delete, it first updates the first record (although i see no obvious changes)
then deletes the second

THEN continues to do 2 more updates on the first..

Sooooooo....

Either my IInterceptor implementation is completly wrong, or i am starting to think in the lines of a bug :s


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Thu Jun 04, 2009 5:32 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Can you post your interceptor code ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Thu Jun 04, 2009 5:41 am 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
There you go..

Code:
using System;
using System.Collections.Generic;
using System.Text;
using NHibernate;
using MyApp.Data.BusinessObjects;
using MyApp.Data.Helpers;
using System.Diagnostics;

namespace MyApp.Data.Interceptors
{
    [Serializable]
    public partial class Interceptor : EmptyInterceptor
    {

        #region "handle delete"
       
        public override

        public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //update some stuff here
           
            for (int i = 0; i < propertyNames.Length; i++)
            {

                if ("Recdeleted".Equals(propertyNames[i]))
                {
                   
                   state[i] = DateTime.Now;
                }
                if ("Recdeleter".Equals(propertyNames[i]))
                {
                    //TODO: also write who did this
                }
            }

            Helpers.MBMessage oMessage = new MBMessage();
            if (entity.GetType() == typeof(Media))
            {
                if ((entity as Media).Published == 1)
                {
                    oMessage.Command = MyApp.Data.Helpers.MBMessage.enumMessageCommand.MEDIA_DELETE;
                    oMessage.MessageText = (entity as Media).Id;
                }

            }else if(entity.GetType()== typeof(SelectionlistMediamember))
            {
                oMessage.Command = MyApp.Data.Helpers.MBMessage.enumMessageCommand.SELECTIONMEMBER_DELETE;
                oMessage.MessageText = (entity as SelectionlistMediamember).Id;

            }
            else if (entity.GetType() == typeof(CollectionlistMediamember))
            {
               
                oMessage.Command = MyApp.Data.Helpers.MBMessage.enumMessageCommand.COLLECTIONMEMBER_DELETE;
                oMessage.MessageText = (entity as SelectionlistMediamember).Id;
            }
            else if (entity.GetType() == typeof(Selectionlist))
            {
               
                // does this cascade ? so all selectionlist members get an auto delete which will be send to the ActiveMQ too ?
                oMessage.Command = MyApp.Data.Helpers.MBMessage.enumMessageCommand.SELECTIONLIST_DELETE;
                oMessage.MessageText = (entity as Selectionlist).Id;
            }
            else if (entity.GetType() == typeof(Collectionlist))
            {
               
                oMessage.Command = MyApp.Data.Helpers.MBMessage.enumMessageCommand.COLLECTIONLIST_DELETE;
                oMessage.MessageText = (entity as Collectionlist).Id.ToString();
            }

            // now send it
            base.OnDelete(entity, id, state, propertyNames, types);
            SendUpdateMessage(oMessage);
           
           
        }

   
        #endregion


        public override bool  OnFlushDirty(object entity, object id, object[] currentState, object[] previousState, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //is called on updates
            Debug.Write("We are handeling a: " + entity.ToString() + types.ToString());

            //handle audit stuff
            for (int i = 0; i < propertyNames.Length; i++)
            {
                if ("Recmodified".Equals(propertyNames[i]))
                {
                    currentState[i] = DateTime.Now;
                }
                if ("Recmodifier".Equals(propertyNames[i]))
                {
                    //TODO: also write who did this
                }
            }
            MBMessage oMessage = new MBMessage();
            if (entity.GetType() == typeof(Media))
            {
               
                if ((entity as Media).Published == 1)
                {
                    oMessage.Command = MBMessage.enumMessageCommand.MEDIA_UPDATE;
                    if ((entity as Media).MediaMember != null)
                    {
                        //there is a child
                        oMessage.MessageText = (entity as Media).MediaMember.Id;
                        SendUpdateMessage(oMessage);
                    }
                    oMessage.MessageText = (entity as Media).Id;

                    SendUpdateMessage(oMessage);
                }

            }else if(entity.GetType() == typeof(SelectionlistMediamember))
            {
                oMessage.Command = MBMessage.enumMessageCommand.SELECTIONMEMBER_UPDATE;
                oMessage.MessageText = (entity as SelectionlistMediamember).Id;
                SendUpdateMessage(oMessage);
            }
           

           return base.OnFlushDirty(entity, id, currentState, previousState, propertyNames, types);
        }


        public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
        {
            //is called on creates

           
            // write information to the queue
            MBMessage oMessage = new MBMessage();
            if (entity.GetType() == typeof(Media))
            {
                // this is handled on publish, we should never let them know anything happend
            }
            else if (entity.GetType() == typeof(File))
            {
                //request a hash of the file
            }
            else if (entity.GetType() == typeof(SelectionlistMediamember))
            {
                //normally, this could not happen, we only can add or delete (undelete ?)
                oMessage.Command = MBMessage.enumMessageCommand.SELECTIONMEMBER_ADD;
                oMessage.MessageText = (entity as SelectionlistMediamember).Id;
                SendUpdateMessage(oMessage);

            }

            //TODO: implement security stuff here., automatic update, create and other auditable stuff should be done here.

            //try to update the property with the reccreated name
            Boolean bChanged = false;
            for (int i = 0; i < propertyNames.Length; i++)
            {
                if ("Reccreated".Equals(propertyNames[i]))
                {
                    state[i] = DateTime.Now;
                    bChanged = true;
                }
                if ("Recmodified".Equals(propertyNames[i]))
                {
                    state[i] = DateTime.Now;
                    bChanged = true;
                }
                if ("Reccreater".Equals(propertyNames[i]))
                {
                    //TODO: also write who did this
                }
            }

            //return bChanged;
          return base.OnSave(entity, id, state, propertyNames, types);
           
        }


        private void SendUpdateMessage(MBMessage Message)
        {
            Helpers.ActiveMQMessageSender oMessageSender = new MyApp.Data.Helpers.ActiveMQMessageSender("tcp://MyBrokerUrl:1414", "record.updates");
          if(Message.Command != MBMessage.enumMessageCommand.NONE)
          {
                oMessageSender.Send(Message);
            }
        }

       
       
    }
}



Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Thu Jun 04, 2009 7:04 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Hmm, I'm not very familiar with intercpetor's. Most of it looks fine in my view. The only thing that comes to my mind is that you have to make sure that you return true from OnFlushDirty() when you make modifications to properties. And EmptyInterceptor.OnFlushDirty() always returns false. It's the same with OnSave() !

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Mon Jun 08, 2009 10:13 am 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
This is driving me insane !.. meanwhile i have stopped using the interceptor code for now (Changing states in the OnDelete are is strongly adviced against anyway)

But still i cannot simple delete a relationship between parent and while. I 'm posting my Mappings now: could someone please just give me an example of a corrrect delete instruction ? I am stuck on this for over a week loosing a lot of time for a simple delete and have contemplated throwing my laptop through the window serveral times ( not to mention the pen's i have chewed on ;-)

Mappings:

Media ( parent)

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TP2.mediabutler.Data.BusinessObjects" assembly="TP2.mediabutler.Data">
   <class name="TP2.mediabutler.Data.BusinessObjects.Media, TP2.mediabutler.Data" table="media" where="deleted = 0" lazy="true">
      <id name="Id" column="id">
          <generator class="assigned" />
      </id>
      <property name="Title" column="title" />
      <property name="Sabam" column="sabam" />
      <property name="Disc" column="disc" />
      <property name="Track" column="track" />
      <property name="Year" column="year" />
      <property name="Duration" column="duration" />
      <property name="Leadin" column="leadin" />
      <property name="Leadout" column="leadout" />
      <property name="Validfrom" column="validfrom" />
      <property name="Validuntil" column="validuntil" />
      <property name="Class" column="class" />
      <property name="Published" column="published" />
      <property name="Reccreated" column="reccreated" />
      <property name="Reccreater" column="reccreater" />
      <property name="Recmodified" column="recmodified" />
      <property name="Recmodifier" column="recmodifier" />
      <property name="Recdeleted" column="recdeleted" />
      <property name="Recdeleter" column="recdeleter" />
      <property name="Deleted" column="deleted" />
      <many-to-one name="Author" column="author" class="Author"/>
      <many-to-one name="MediaMember" column="childid" class="Media"/>
      <many-to-one name="Country" column="country" class="Country"/>
      <many-to-one name="File1" column="filedefault" class="File"/>
      <many-to-one name="File2" column="filesource" class="File"/>
      <many-to-one name="FileType" column="filetype" class="FileType"/>
      <many-to-one name="MediaGender" column="gender" class="MediaGender"/>
      <many-to-one name="MediaGenre" column="genre" class="MediaGenre"/>
      <many-to-one name="MediaId3genre" column="id3genre" class="MediaId3genre"/>
      <many-to-one name="Language" column="language" class="Language"/>
      <many-to-one name="Library" column="library" class="Library"/>
      <many-to-one name="MediaStatus" column="status" class="MediaStatus"/>
      <many-to-one name="MediaType" column="mediatype" class="MediaType"/>
      <many-to-one name="MediaTempo" column="tempo" class="MediaTempo"/>
      <many-to-one name="MediaVoice" column="voice" class="MediaVoice"/>
      <bag name="CollectionlistMediamembers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
         <key column="media"></key>
         <one-to-many class="CollectionlistMediamember"></one-to-many>
      </bag>
      <bag name="Files" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
         <key column="media_id"></key>
         <one-to-many class="File"></one-to-many>
      </bag>
      <bag name="MediaCustomers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
         <key column="media"></key>
         <one-to-many class="MediaCustomer"></one-to-many>
      </bag>
      <bag name="PlaylistMedia" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
         <key column="media"></key>
         <one-to-many class="PlaylistMedium"></one-to-many>
      </bag>
      <bag name="SelectionlistMediamembers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
         <key column="media"></key>
         <one-to-many class="SelectionlistMediamember"></one-to-many>
      </bag>
      <sql-delete>update media set deleted = 1 where id = ?</sql-delete>
   </class>
</hibernate-mapping>


selectionlist

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TP2.mediabutler.Data.BusinessObjects" assembly="TP2.mediabutler.Data">
   <class name="TP2.mediabutler.Data.BusinessObjects.Selectionlist, TP2.mediabutler.Data" table="selectionlists" where="deleted = 0" lazy="true">
      <id name="Id" column="id">
          <generator class="assigned" />
      </id>
      <property name="Name" column="name" />
      <property name="Reccreated" column="reccreated" />
      <property name="Reccreater" column="reccreater" />
      <property name="Recmodified" column="recmodified" />
      <property name="Recmodifier" column="recmodifier" />
      <property name="Recdeleted" column="recdeleted" />
      <property name="Recdeleter" column="recdeleter" />
      <property name="Deleted" column="deleted" />
      <bag name="PlaylistSelectionlists" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
         <key column="selectionlist"></key>
         <one-to-many class="PlaylistSelectionlist"></one-to-many>
      </bag>
      <bag name="SelectionlistMediamembers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
         <key column="selectionlist"></key>
         <one-to-many class="SelectionlistMediamember"></one-to-many>
      </bag>
      <sql-delete>update selectionlists set deleted = 1 where id = ?</sql-delete>
   </class>
</hibernate-mapping>



Selecitonlistmediamember ( intermediate table linking media and selectionlsits)

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="TP2.mediabutler.Data.BusinessObjects" assembly="TP2.mediabutler.Data">
   <class name="TP2.mediabutler.Data.BusinessObjects.SelectionlistMediamember, TP2.mediabutler.Data" table="selectionlist_mediamembers" where="deleted = 0" lazy="true">
      <id name="Id" column="id">
          <generator class="assigned" />
      </id>
      <property name="Reccreated" column="reccreated" />
      <property name="Reccreater" column="reccreater" />
      <property name="Recmodified" column="recmodified" />
      <property name="Recmodifier" column="recmodifier" />
      <property name="Recdeleted" column="recdeleted" />
      <property name="Recdeleter" column="recdeleter" />
      <property name="Deleted" column="deleted" />
      <many-to-one name="Media" column="media" class="Media"/>
      <many-to-one name="Selectionlist" column="selectionlist" class="Selectionlist"/>
      <sql-delete>update selectionlist_mediamembers set deleted = 1 where id = ?</sql-delete>
   </class>
</hibernate-mapping>



Delete instruction from my app

Code:
   
            //get the media:

            Media oMedia = oMediaManager.GetById(dgvResult.SelectedRows[0].Cells["Id"].Value.ToString());
            SelectionlistMediamember oSelectionlistMediaMemberToDelete = null;
            foreach (SelectionlistMediamember oSelMember in oMedia.SelectionlistMediamembers)
            {
                if (oSelMember.Selectionlist == _selectionlist)
                {
                    oSelectionlistMediaMemberToDelete = oSelMember;
                    break;
                }
            }

            if (oSelectionlistMediaMemberToDelete != null)
            {
               
                if (MessageBox.Show("Are you sure you want to remove this media from the selectionlist: " + Environment.NewLine + Environment.NewLine + oMedia.Author.Name + " - " + oMedia.Title + " (Selectionmemberid: " + oSelectionlistMediaMemberToDelete.Id + " )", "WARNING: Are you sure ?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    try
                    {
                        oMediaManager.Session.GetISession().Flush();
                        oMedia.SelectionlistMediamembers.Remove(oSelectionlistMediaMemberToDelete);
                        Selectionlist.SelectionlistMediamembers.Remove(oSelectionlistMediaMemberToDelete);
                       
                        oMediaManager.Session.GetISession().Delete(oSelectionlistMediaMemberToDelete);
                        //oMediaManager.Update(oMedia);
                        //oMediaManager.Session.GetISession().Save(Selectionlist);

                        oMediaManager.Session.GetISession().Flush();
                       
                        BtnSearch_Click(null, null);
                    }
                    catch (Exception ex)
                    {
                       
                        MessageBox.Show(ex.ToString());
                        //throw;
                    }

                }
            }


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Tue Jun 09, 2009 8:10 am 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
Feels like i am talking to myself but i keep going ;-)

I was checking some other code i remembered where i do this delete but from a different approach.. and tadaa.. it works there simply by doing:

Code:
oMedia.SelectionListMediaMembers.remove(oSelectionlistMediaMemberTODelete);
oMediaManager.Save(oMedia);
oMediaManager.Session.CommitChanges();


et voila.. it's done.. but when i try the same thing in the form i am working on now.. it doesn not work :s

What i can tell you, is that my Laptop is dangerously close to learning how to fly...


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Wed Jun 10, 2009 2:30 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
I'm not sure what is currently working for you and what not:

I asume using a custom delete that doesnot really delete (<sql-delete>update media set deleted = 1 where id = ?</sql-delete>) isn't working. What about a normal delete (remember to remove the sql-delete section from the mapping) ? Isn't even that working ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Wed Jun 10, 2009 4:51 am 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
The issue is the same with both actually.. I get the error(s) both with a custom delete command AND a standard delete from the table..


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Wed Jun 10, 2009 5:07 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Errors like exceptions ? In that case, pls post the exceptions (and check for inner exceptions). Or is it just the wrong result ?

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Thu Jun 11, 2009 5:21 am 
Newbie

Joined: Sat May 30, 2009 11:42 am
Posts: 15
The exception:

Code:
NHibernate.ObjectDeletedException was unhandled
  Message="deleted object would be re-saved by cascade (remove deleted object from associations)[TP2.mediabutler.Data.BusinessObjects.SelectionlistMediamember#9324f957-270c-4458-a28e-79b747084871]"
  Source="NHibernate"
  EntityName="TP2.mediabutler.Data.BusinessObjects.SelectionlistMediamember"
  StackTrace:
       at NHibernate.Impl.SessionImpl.ForceFlush(EntityEntry entityEntry)
       at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.EntityIsTransient(SaveOrUpdateEvent event)
       at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.PerformSaveOrUpdate(SaveOrUpdateEvent event)
       at NHibernate.Event.Default.DefaultSaveOrUpdateEventListener.OnSaveOrUpdate(SaveOrUpdateEvent event)
       at NHibernate.Impl.SessionImpl.FireSaveOrUpdate(SaveOrUpdateEvent event)
       at NHibernate.Impl.SessionImpl.SaveOrUpdate(String entityName, Object obj)
       at NHibernate.Engine.CascadingAction.SaveUpdateCascadingAction.Cascade(IEventSource session, Object child, String entityName, Object anything, Boolean isCascadeDeleteEnabled)
       at NHibernate.Engine.Cascade.CascadeToOne(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
       at NHibernate.Engine.Cascade.CascadeAssociation(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
       at NHibernate.Engine.Cascade.CascadeProperty(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
       at NHibernate.Engine.Cascade.CascadeCollectionElements(Object child, CollectionType collectionType, CascadeStyle style, IType elemType, Object anything, Boolean isCascadeDeleteEnabled)
       at NHibernate.Engine.Cascade.CascadeCollection(Object child, CascadeStyle style, Object anything, CollectionType type)
       at NHibernate.Engine.Cascade.CascadeAssociation(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
       at NHibernate.Engine.Cascade.CascadeProperty(Object child, IType type, CascadeStyle style, Object anything, Boolean isCascadeDeleteEnabled)
       at NHibernate.Engine.Cascade.CascadeOn(IEntityPersister persister, Object parent, Object anything)
       at NHibernate.Event.Default.AbstractFlushingEventListener.CascadeOnFlush(IEventSource session, IEntityPersister persister, Object key, Object anything)
       at NHibernate.Event.Default.AbstractFlushingEventListener.PrepareEntityFlushes(IEventSource session)
       at NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event)
       at NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event)
       at NHibernate.Impl.SessionImpl.Flush()
       at TP2.mediabutler.Data.Base.NHibernateSession.CommitChanges() in D:\tp2dev\TP2.mediabutler\TP2.mediabutler.Data\Base\NHibernateSession.cs:line 76
       at TP2.mediabutler.client.Forms.FrmMediaSearch.tsRemoveSelectionList_Click(Object sender, EventArgs e) in D:\tp2dev\TP2.mediabutler\Mediabutler\Forms\FrmMediaSearch.cs:line 205
       at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
       at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
       at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
       at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
       at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ToolStrip.WndProc(Message& m)
       at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Mediabutler.Program.Main() in D:\tp2dev\TP2.mediabutler\Mediabutler\Program.cs:line 21
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()



but the innerexception = null....

Can someone please post the correct syntax to do this type of delete normally ?

I would think:

remove object from all collections it is in
delete object
update objects containing the object in its collection(s)
Commit Transaction


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Thu Jun 11, 2009 6:31 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Quote:
remove object from all collections it is in
delete object
update objects containing the object in its collection(s)


If the object is still member of other collections, you can't delete it ! You have to remove it from all collections. But if you only want to remove it from the collection, then you don't have to delete it.

_________________
--Wolfgang


Top
 Profile  
 
 Post subject: Re: Delete not executing
PostPosted: Thu Jun 11, 2009 8:04 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Code:
oMediaManager.Session.GetISession().Flush();
                        oMedia.SelectionlistMediamembers.Remove(oSelectionlistMediaMemberToDelete);
                        Selectionlist.SelectionlistMediamembers.Remove(oSelectionlistMediaMemberToDelete);
                       
                        oMediaManager.Session.GetISession().Delete(oSelectionlistMediaMemberToDelete);
                        //oMediaManager.Update(oMedia);
                        //oMediaManager.Session.GetISession().Save(Selectionlist);

                        oMediaManager.Session.GetISession().Flush();


Try the following before flushing the session:

Code:
oSelectionlistMediaMemberToDelete.SelectionList = null;
oSelectionlistMediaMemberToDelete.Media = null;


If that does not help, try to enable debug logging and check the order for the operations.

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 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.