I try to insert an entity violating an unique key.
Postgres and RemoteDB are raising UK-violation as expected.
But Rollback in ObjectManager.SaveOrUpdate raises “not in Transaction”.
TObjectManager.SaveOrUpdate
...
DoCommit(Transaction);
except
DoRollback(Transaction);
raise;
end;
end;
On Server Side TRemoteDatabase.Commit is called and set FTransaction := nil;
Trans.Commit is raising the UK-exception, so that TObjectManager is calling DoRollback.
DoRollback is leading to TRemoteDatabase.Rollback, that raises Exception.Create('Cannot rollback. Database is not in a transaction.'); because FTransaction has already been set to nil in Commit.
changing Commit like this would fix my issue, so that I get the expected UK-Exception:
procedure TRemoteDatabase.Commit;
begin
if FTransaction <> nil then
begin
FTransaction.Commit;
FTransaction := nil;
end
else
raise Exception.Create('Cannot commit. Database is not in a transaction.');
end;
and because they look similar I also changed Rollback:
procedure TRemoteDatabase.Rollback;
begin
if FTransaction <> nil then
begin
FTransaction.Rollback;
FTransaction := nil;
end
else
raise Exception.Create('Cannot rollback. Database is not in a transaction.');
end;