Loading...

nhusers@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

[nhusers] Unexpected row count expected 1 but was 0 problem epitka Wed Sep 30 06:01:15 2009

I cannot persist my entity and I get the message above but only when I
use event listener. Does anybody know why? Here are the facts:

NHibernate 2.1, FluentNHibernate 1.0, Castle Dynamic proxy provider


Mapping for MetaProject:

 public class MetaProjectMap : ClassMap<MetaProject>
    {
        public MetaProjectMap()
        {
            DefaultAccess.ReadOnlyPropertyThroughCamelCaseField
(CamelCasePrefix.Underscore);

            Table("dnnSphere_Project");

            Id(x => x.Id).Access.LowerCaseField
(Prefix.Underscore).GeneratedBy.HiLo("1").UnsavedValue(0); ;

            Map(x => x.Name).Column("Name").Unique().Not.Nullable
().Length(50);
            Map(x => x.Description).Column("Description").Length(50);

            HasMany<MetaPackage>(x => x.MetaPackages).Table
("dnnSphere_Package").KeyColumn("Id")
                .Inverse().LazyLoad().Cascade.AllDeleteOrphan()
                .Access.ReadOnlyPropertyThroughCamelCaseField
(Prefix.Underscore)
                .CollectionType
("dnnSphere.NHibernate.Collections.PersistentBagType`1
[[dnnSphere.Meta.Model.MetaPackage, dnnSphere.Meta]],
dnnSphere.NHibernate.Collections");
        }
    }

NHibernate config file:

 <property
name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory,
NHibernate.ByteCode.Castle</property>

 <property name="current_session_context_class">
        web
 </property>

<event type="save-<listener
class="dnnSphere.Meta.NHibernate.SaveOrUpdateEventListener,dnnSphere.Meta"/
>
        <listener
class="NHibernate.Event.Default.DefaultUpdateEventListener,
NHibernate"/>
  </event>

Code that I am testing this with:

 ISession session = NHibernateHelper.Instance.GetCurrentSession();
            try
            {
                session.BeginTransaction();
                metaProject = MetaProject.Create();
                metaProject.Name = txtName.Text;
                metaProject.Description = txtDescription.Text;
                session.SaveOrUpdate(metaProject);
                session.Flush();

                var n =
NHibernateHelper.Instance.SessionFactory.Statistics.EntityInsertCount;

                session.Transaction.Commit();
            }
            catch (Exception ex)
            {
                session.Transaction.Rollback();
                throw;
            }
            finally
            {
                session.Close();
            }

Event listener:

  public class SaveOrUpdateEventListener : ISaveOrUpdateEventListener
    {

        public void OnSaveOrUpdate(SaveOrUpdateEvent @event)
        {
            IPersistentObjectLifeCycle o = @event.Entity as
IPersistentObjectLifeCycle;

            if (o != null)
            {
                o.OnSaveOrUpdate();
            }

        }
    }
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---