-->
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.  [ 1 post ] 
Author Message
 Post subject: Bug? - DefaultEvictEventListener
PostPosted: Wed Jan 21, 2009 1:24 am 
Newbie

Joined: Wed Jan 21, 2009 12:56 am
Posts: 1
From the trunk.

In AbstractSaveEventListener.PerformSaveOrReplicate

source.PersistenceContext.AddEntry(...) is called before OnSave
source.PersistenceContext.AddEntity(...) is called after OnSave

If an interceptor throws for an association, AddEntity is never called for that association

So if you call Session.Evict on the root of that object a KeyNotFoundException is thrown (for GUID Id's, a different one for others)

Because In DefaultEvictEventListener:

if the object is NOT an INHibernateProxy, it removes the entry, then the entity without checking whether there is an entity to remove. Thus in my situation it throws an exception.

Attached a test to drop into the Nhibernate.Tests project

Code:
using System;
using System.Collections;
using NHibernate.Test.Cascade;
using NHibernate.Type;
using NUnit.Framework;

namespace NHibernate.Test.Interceptor
{
    [TestFixture]
    public class EvictProblemFixture : TestCase
    {
        protected override string MappingsAssembly
        {
            get { return "NHibernate.Test"; }
        }

        protected override IList Mappings
        {
            get { return new[] { "Cascade.Job.hbm.xml", "Cascade.JobBatch.hbm.xml" }; }
        }

        [Test]
        public void EvictWorksAfterOnSaveError()
        {
            ISession s = OpenSession(new ThrowingInterceptor());
            ITransaction txn = s.BeginTransaction();

            JobBatch batch = new JobBatch(DateTime.Now);
            batch.CreateJob().ProcessingInstructions = "Just do it!";
            batch.CreateJob().ProcessingInstructions = "Throw";

            try
            {
                s.SaveOrUpdate(batch);
            }
            catch(Exception)
            {
                s.Evict(batch);
            }
            finally
            {
                txn.Rollback();
                s.Close();
            }
        }

        public class ThrowingInterceptor : EmptyInterceptor
        {
            public override bool OnSave(object entity, object id, object[] state, string[] propertyNames, IType[] types)
            {
               if(entity is Job && ((Job)entity).ProcessingInstructions == "Throw")
                    throw new Exception();

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

}

[/quote]


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.