I have a following test case, which fails at the last line:
[Test]
public void TestExplicitFlush() {
Entity e1 = new Entity("test1");
Entity e2 = new Entity("test2");
using (new SessionScope(FlushAction.Never)) {
e1.Create();
e2.Create();
}
using (new SessionScope(FlushAction.Never)) {
using (TransactionScope tx = new
TransactionScope(OnDispose.Rollback)) {
Entity e2a = Entity.Find(e2.Id);
e2a.Name = "changed";
tx.VoteCommit();
}
using (new TransactionScope(OnDispose.Rollback)) {
Entity[] changedEntities =
Entity.FindAllByProperty("Name", "changed");
Assert.AreEqual(1, changedEntities.Length);
Entity e2a = changedEntities[0];
e2a.Delete();
SessionScope.Current.Flush();
Assert.AreEqual(0, Entity.FindAllByProperty("Name",
"changed").Length);
}
}
}
the problem is that SessionScope.Current.Flush() seem to have no effect
in this case. The test passes if I comment out the first transaction
that changes the entity name (and adjust the FindAll parameter of
course). Is this a bug or am I missing something?
Oh, and the Entity class is just a pair of Id and Name.
Regards,
Vladimir Okhotnikov
--
Cheers,
hamilton verissimo
ham...@castlestronghold.com
http://www.castlestronghold.com/
> Assert.AreEqual (0, Entity.FindAllByProperty("Name",
> "changed").Length);
> }
> }
> }
>
>
> the problem is that SessionScope.Current.Flush () seem to have no effect
public override void Flush()
{
if (mode == TransactionMode.Inherits &&
parentTransactionScope != null)
{
parentTransactionScope.Flush();
}
if (parentSimpleScope != null)
{
parentSimpleScope.Flush();
}
base.Flush();
}
solves the problem (and the other AR tests still pass), but I'm not sure
this is the best approach - maybe it is better to register sessions in
key2Session dictionary on TransactionScope.GetSession call?
Regards,
Vladimir Okhotnikov
Vladimir Okhotnikov wrote on 1/22/2008 1:54 PM:
> Using ReadUncommitted did not change anything. After spending some
> time with debugger, it is likely that that the problem is caused by
> the fact the following difference:
>
> - if a transaction scope is first in a session scope, the transaction
> scope has one NHibernate session in its key2Session disctionary
> - if the same transaction scope is second in a session scope, its
> key2Session dictionary is empty, hence Flush does not find any
> sessions to flush
>
> I'm going to look into this a bit more.
>
> Regards,
> Vladimir Okhotnikov
>
> On 21/01/2008, *Hamilton Verissimo* <ham...@castlestronghold.com
> <mailto:ham...@castlestronghold.com>> wrote:
>
>
> Indeed. Can you change the transactions to use
> IsolationLevel.ReadUncommitted?
>
> On 1/18/08, Vladimir Okhotnikov < vokho...@gmail.com
> ham...@castlestronghold.com <mailto:ham...@castlestronghold.com>
> http://www.castlestronghold.com/
>
> >
>
any chance of the patch to be applied?
Regards,
Vladimir Okhotnikov