I am trying to wrap a script of custom DSL commands in to a single transaction that can be rolled back at any point during execution.
This is a very distilled example of a session saving an object, rolling back, but not removing the object. Is this normal behavior, or what am I doing wrong?
Hibernate version: 1.2
Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="false">
<class name="Basic.A, Basic" table="A">
<id name="id" column="ID" access="field" unsaved-value="0">
<generator class="identity" />
</id>
<property name="Name" column="Name"/>
</class>
</hibernate-mapping>
Name and version of the database you are using: Sql Server 2005
This is my code:Code:
[TestFixture]
public class TestOut
{
[TestFixtureSetUp]
public void Setup()
{
Configuration _configuration = new Configuration();
_configuration.Configure();
SchemaExport _schemaExport = new SchemaExport(_configuration);
_schemaExport.Drop(true, true);
_schemaExport.Create(true, true);
}
[TestFixtureTearDown]
public void TearDown()
{
}
[Test]
public void Test1()
{
ISessionFactory _sessionFactory = new Configuration().Configure().BuildSessionFactory();
using (ISession _session = _sessionFactory.OpenSession())
{
_session.FlushMode = FlushMode.Never;
ITransaction _transaction2 = _session.BeginTransaction(IsolationLevel.Serializable);
A a = new A("I should be deleted!");
_session.SaveOrUpdate(a);
_transaction2.Rollback();
}
}
}
This is the COMPLETE sql output, according to the profilerCode:
exec sp_reset_connection
go
exec sp_executesql N'INSERT INTO PPSLab.dbo.A (Name) VALUES (@p0); select SCOPE_IDENTITY()',N'@p0 nvarchar(20)',@p0=N'I should
be deleted!'
go
Why is the rollback NOT removing the saved object?
Why is the insert occurring IMMEDIATELY on the SaveOrUpdate call before a flush or commit?
Thanks in advance to anyone who can help me with this sanity check!