-->
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: Bug in Evict with versioning
PostPosted: Mon Jan 30, 2006 12:41 pm 
Newbie

Joined: Thu May 12, 2005 2:26 am
Posts: 4
So I’m pretty sure I’ve found a bug.
Add the attached test to FooBarTests.cs

1 Run it as it is and it works.
2 Modify the code by adding ! before SHOULDNT_THIS_BE_ENOUGH (that is choose the Evict solution).

It seems that even if I’ve re-read the One instance getting it to understand that its version (V) is 1, 0 is used in the update statement. The 0 was the original value when first reading the instance. Run the code.

Regards, Ingo

[Test]
public void IsThisABug()
{
long key;
using (ISession s = OpenSession())
{
One one = new One();
one.Manies = new HashedSet();
s.Save(one);
s.Flush();
key = one.Key;
}

// Intending to update
ISession s1 = OpenSession();
One o1 = (One)s1.Get(typeof(One), key);
Assert.IsNotNull(o1);
Assert.AreEqual(0, o1.V);

// Update in another session beats u to it
ISession s2 = OpenSession();
One o2 = (One)s2.Get(typeof(One), key);
Assert.IsNotNull(o2);
o2.X = 2;
s2.Flush();
Assert.AreEqual(1, o2.V);
s2.Dispose();

// slow as I am, now I'm gonna try to update
o1.X = 1;
try
{
s1.Flush();
Assert.Fail("Should fail");
}
catch(NHibernate.StaleObjectStateException)
{
// oh, well. Prepare to retry
#if SHOULDNT_THIS_BE_ENOUGH
s1.Evict(o1);
#else
s1.Dispose();
s1 = OpenSession();
#endif
}

// let's read it from db again and retry the update
o1 = (One)s1.Get(typeof(One), key);
Assert.AreEqual(1, o1.V);
o1.X = 1;
// with Evict, this fails again with StaleObjectStateException
// note that o1.V == 1 is however correct with Evict
s1.Flush();
Assert.AreEqual(2, o1.V);

s1.Dispose();

using (ISession s = OpenSession())
{
s.Delete( "from o in class NHibernate.DomainModel.One" );
s.Flush();
}
}


Top
 Profile  
 
 Post subject: Re: Bug in Evict with versioning
PostPosted: Mon Jan 30, 2006 5:09 pm 
Newbie

Joined: Thu May 12, 2005 2:26 am
Posts: 4
I'm so sorry. I ended up in the wrong forum with this post. I ment to post in NHibernate.
Once again, sorry.
/ingo

lundbergi wrote:
So I’m pretty sure I’ve found a bug.
Add the attached test to FooBarTests.cs

1 Run it as it is and it works.
2 Modify the code by adding ! before SHOULDNT_THIS_BE_ENOUGH (that is choose the Evict solution).

It seems that even if I’ve re-read the One instance getting it to understand that its version (V) is 1, 0 is used in the update statement. The 0 was the original value when first reading the instance. Run the code.

Regards, Ingo

[Test]
public void IsThisABug()
{
long key;
using (ISession s = OpenSession())
{
One one = new One();
one.Manies = new HashedSet();
s.Save(one);
s.Flush();
key = one.Key;
}

// Intending to update
ISession s1 = OpenSession();
One o1 = (One)s1.Get(typeof(One), key);
Assert.IsNotNull(o1);
Assert.AreEqual(0, o1.V);

// Update in another session beats u to it
ISession s2 = OpenSession();
One o2 = (One)s2.Get(typeof(One), key);
Assert.IsNotNull(o2);
o2.X = 2;
s2.Flush();
Assert.AreEqual(1, o2.V);
s2.Dispose();

// slow as I am, now I'm gonna try to update
o1.X = 1;
try
{
s1.Flush();
Assert.Fail("Should fail");
}
catch(NHibernate.StaleObjectStateException)
{
// oh, well. Prepare to retry
#if SHOULDNT_THIS_BE_ENOUGH
s1.Evict(o1);
#else
s1.Dispose();
s1 = OpenSession();
#endif
}

// let's read it from db again and retry the update
o1 = (One)s1.Get(typeof(One), key);
Assert.AreEqual(1, o1.V);
o1.X = 1;
// with Evict, this fails again with StaleObjectStateException
// note that o1.V == 1 is however correct with Evict
s1.Flush();
Assert.AreEqual(2, o1.V);

s1.Dispose();

using (ISession s = OpenSession())
{
s.Delete( "from o in class NHibernate.DomainModel.One" );
s.Flush();
}
}


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.