Identity Manager

Removing Object from UnitOfWork

Hi All, 


I am trying to add some error handling around the UnitOfWork methods.  I have something similar to below

Using uow = session.StartUnitOfWork()

  For each Person in myCollection

    Dim newPerson As IEntity = session.Source.CreateNew("Person")

    bag.PutValue(myField, newValue)

      bag.ChangeEntity(session, newPerson, True)
    Catch ex As Exception
      'logout: ViException.ErrorString(ex)))
    End Try



End Using


In some instances bad data causes the uow.Put() method to throw an error and the exception is triggered, however from that point on I am no longer able to use the uow object as it receives this error:

[810300] This unit of work contained errors and can't be used for further operations.

So what I am after is a way to remove the last object added to the UnitOfWork so it can continue processing.

I see there are methods such as uow.flush() and uow.dispose()

Has anyone used these methods?  I am running version 7 and my Object Layer documentation doesn't seem to work since the dell hosted urls were closed down, so I haven't been able to find any documentation on these methods as they are not used in the sample scripts.  Does one of these methods allow the last object to be removed from the UnitOfWork, so I could call it from a finally block?

I could add additional validation to the data coming in to try and prevent the error occurring, however it would be nice to have the error handled and not prevent the remaining bulk updates from occurring.

No Data
  • Hi

    a UnitOfWork is one transaction. If your UnitOfWork already caused database operations (Insert/Update/Delete) and an error occurs a rollback is required. The message "[810300] This unit of work contained errors and can't be used for further operations." indicates this state.
    A UnitOfWork can be configured to tolerate high-level errors like "The email address is not valid" while performing a UnitOfWork.Put. This behavior is activated by setting the property ContinueOnError to true. If the UnitOfWork property Invalid is false after an error occurred, the error was tolerated and the current UnitOfWork is still usable. In this case the error-causing, faulty object was not added to the UnitOfWork. You should be able to continue the script.

    You should never call uow.flush() or uow.dispose() unless you are 100% certain what you are doing.

No Data