After an NH/AR exception the session cannot be used anymore, so you have to create a new one. If you use ValidateIsUnique instead, the validation engine checks before flushing by running a select against the table. If the validator throws, you can still use the session after correcting the error.
-Markus 2009/7/20 Gerdus van Zyl <[email protected]> > > Hi, > > I have an unique constraint in the database that throws an exception > but in handling the exception I have to scope.dispose() and create a > new scope otherwise it doesn't seem to send the changes I made to the > object to the database and instead sends the old nonworking state. Is > this this recommended way to handle this? > > code below: > Public Sub GLaccountNoDuplicatesDatabaseUniqueConstraint() > Dim scope As New SessionScope(FlushAction.Never) > > Dim accs As IList(Of GL.Glaccount) > Dim acc As GL.Glaccount > Dim accdup As GL.Glaccount > > accs = GL.Glaccount.FindAll() > acc = accs(0) > accdup = accs(1) > > accdup.description = acc.description > > accdup.Save() > Try > scope.Flush() > Assert.Fail("Constraint failed") > Catch ex As SmartDatabaseConstraintException > 'the exception is expected the two lines below not > scope.Dispose() > scope = New SessionScope(FlushAction.Never) > End Try > > accdup.description = acc.description + "2" > > scope.Flush() > > scope.Dispose() > > End Sub > > ps. I use a exception converter see it here: > > http://stackoverflow.com/questions/1137521/nhibernate-castle-activerecord-how-to-get-object-that-caused-database-exceptio > > Thanks, > Gerdus > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en -~----------~----~----~----~------~----~------~--~---
