Transaction not rolling back - who's bug is this?

0 views
Skip to first unread message

acl123

unread,
Oct 18, 2009, 8:54:42 PM10/18/09
to nhusers
The following code demonstrates a misleading situation in which data
is committed to the database, even though commit is never called on a
transaction.

Could anyone explain why?

[TestFixture]
public class TestFixture
{
[Test]
public void Test()
{
var config = DoConfiguration();

using(var factory = config.BuildSessionFactory())
{
using (var session = factory.OpenSession())
{
CallSessionContext.Bind(session);

using(new TransactionScope())
{
using (session.BeginTransaction())
{
var myEntity = session.CreateQuery
("from myEntity").List<MyEntity>()[0];

myEntity.Name = "test name";
}

var myEntity2 = session.CreateQuery("from
myEntity").List<MyEntity>()[0];

myEntity2.Name = "test name";

session.Flush();
}

CallSessionContext.Unbind(factory);
}
}
}
}

Anne Epstein

unread,
Oct 18, 2009, 11:47:27 PM10/18/09
to nhu...@googlegroups.com

Fabio Maulo

unread,
Oct 19, 2009, 1:23:28 AM10/19/09
to nhu...@googlegroups.com
your are calling Flush

2009/10/18 acl123 <andrewc...@gmail.com>



--
Fabio Maulo

webpaul

unread,
Oct 19, 2009, 9:31:10 AM10/19/09
to nhusers
Not sure if this is the recommended way, but I set autoflush to never
and manually call both flush and commit (though I have my base
repository commit call flush automatically) that way I know exactly
when these things happen. After reading ayende's article I realized
that is how I have been dodging this bullet as I have never seen the
behavior you describe. I tend to setup transactions in test and call
flush to make sure it has gone to DB but don't want it committed, then
at the end of the test I rollback and no changes are persisted which
works quite well.

On Oct 19, 12:23 am, Fabio Maulo <fabioma...@gmail.com> wrote:
> your are calling Flush
>
> 2009/10/18 acl123 <andrewclawre...@gmail.com>
> Fabio Maulo- Hide quoted text -
>
> - Show quoted text -

acl123

unread,
Oct 19, 2009, 8:14:37 PM10/19/09
to nhusers
Ok thanks, my bigger problem is here:
http://groups.google.com/group/nhusers/browse_thread/thread/64d608afc2cd01c3

On Oct 19, 4:23 pm, Fabio Maulo <fabioma...@gmail.com> wrote:
> your are calling Flush
>
> 2009/10/18 acl123 <andrewclawre...@gmail.com>
Reply all
Reply to author
Forward
0 new messages