-->
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.  [ 1 post ] 
Author Message
 Post subject: ITransaction rollback inserts
PostPosted: Wed Apr 18, 2007 10:35 am 
Newbie

Joined: Wed Dec 20, 2006 12:34 pm
Posts: 13
NHibernate 1.0.3.0
MySQL 5

I am attempting to write a generic insert function for a datalayer object. Everything work great but i cannot get the transaction to rollback on an exception.

Code:
Public Function SaveObjectsWithTransaction(ByVal o1 As Object, ByVal o2 As Object) As DataLayerResult

        Dim session As ISession = GetSession()
        Dim dbTrnx As ITransaction = session.BeginTransaction()

        Try
            session.Save(o1)
            session.Save(o2)
            dbTrnx.Commit()
            Return DataLayerResult.Success
        Catch e1 As StaleObjectStateException
            dbTrnx.Rollback()
            Return DataLayerResult.StaleObjectFailure
        Catch e2 As HibernateException
            dbTrnx.Rollback()
            Return DataLayerResult.ServiceFailure
        Finally
            session.Close()
        End Try

    End Function


To test this i force a HibernateException via an invalid foreign key constraint on object 2 (o2). So while debugging object 1(o1) gets inserted into the database even though the transaction has not been committed, then an exception is thrown form session.Save(o2), which is caught, then dbTrnx.rollback - which has no effect and close the session.

After reading the documentation is seems that the problem may lie in my mapping file id being native. The id for o1 is listed below:

<id name="Id" column="ACCOUNT_ID" type="int">
<generator class="native" />
</id>


If this is the case can anyone offer a reasonable alternative to using the native id or any other solution.

Thanks in advance


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.