This error indicates that an update or delete of a record failed.
When Servoy performs an update or delete on a record, it checks whether =
the database reports back that the record was actually updated or deleted. =
If the database reports that the update or delete did not take place, the <=
code>Update/insert failed, unexpected nr of records affected: expected 1, a=
ctual 0 error is reported.
The database can report that the update or delete failed when based on t=
he SQL executed on the database no record was found to update or delete. Th=
ere could be different reasons for the database not being able to locate th=
e record to update or delete, some of which are explained below.
One scenario that may result in =
this error is when records are created that do not match the active filters=
: when a record is deleted or updated in the database the active fil=
ter conditions (FoundSet filters and table filters) are added to the generated sql. If the conditions are not met, the update will not=
happen and Servoy throws this exception. For example, a table filte=
r 'tenant_id =3D 4' is active and a new customer record is created with nul=
l value for the tenant_id. This record can be saved in the database, but a =
consecutive update or delete will fail (update customers set name =3D ? whe=
re id =3D ? and tenant_id =3D 4).
Another scenario that may cause =
this error to be raised is when the record modified/deleted outside Servoy =
and Servoy is not notified. For example, an orders record is deleted=
from outside of Servoy while it is loaded in a Servoy Client and that Serv=
oy Client then attempt to delete it. That delete fails with the above error=
because the database reports that delete from Servoy did not occur, becaus=
e the record didn't exist.
By default the Servoy Application Server will raise this exception when =
such scenario occurs. It is possible to suppress these errors by setting th=
e server property servoy.server.throwErrorOnUnexpectedUpdateCount to false
. However, this should be used with care and only =
as a temporary solution until the underlying problem has been discovered an=
d fixed.