-->
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: Sanity check: Transaction not rolling back save operations
PostPosted: Thu Jan 03, 2008 1:00 pm 
Beginner
Beginner

Joined: Tue Sep 04, 2007 12:36 pm
Posts: 23
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 profiler
Code:
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!

_________________
^^If this post helped you, make sure to rate it Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 07, 2008 5:52 pm 
Beginner
Beginner

Joined: Tue Sep 04, 2007 12:36 pm
Posts: 23
My sanity has been saved.
Indeed this _does_ work after all.

My SQL profiler is the failure here, by default, SQL server 2005 does not show the BEGIN TRAN/ROLLBACK TRAN commands unless properly configured. This is a false alarm, everything works fine.

_________________
^^If this post helped you, make sure to rate it Thanks!


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.