Check the deletion of a primary objects ManyToOne relationships
While working on the DocumentFlow branch, I discovered a bug that was resulting in duplicated phantom objects in the database. This was discovered as I introduced the Organisation change to the domain model, so was doing some manual checks.
I found phantom deletion objects in the deletion and system_id table. After a running with runtest there should have been 4 such rows in the database, but there were 8. Debugging showed that extra rows were added during a PUT operation. Upon inspection, the following line was found to be the culprit:
existing.setReferenceDeletion(incoming.getReferenceDeletion());
What's happening here is that the DocumentDescription / Deletion relationship is such that a PERSIST will automatically result in an object being written to the database. When the reference to the deletion is overwritten, a new object is persisted to the database. The offending line was replaced with
existingDeletion.setDeletionBy(incomingDeletion.getDeletionBy());
existingDeletion.setDeletionDate(incomingDeletion.getDeletionDate());
existingDeletion.setDeletionType(incomingDeletion.getDeletionType());
So here we simply force an update to the values rather than overwriting the reference. It is almost certain this has been an issue in nikita for a long time, and makes me think that we should have some sort of test that checks the database for orphans after running runtest.
I need to make an own branch where I go through all ManyToOne relationships and check if this problem is applicable.