Hi Alan,
the sequence of statements is the same in both cases, just the UPDATE of the Receipt is missing...
This is a good case (Sorry for the mix of German and English Table names. I translated the real Table name to RECEIPT fopr your convenience) :
2026-02-12 16:10:32,246 select next value for db2inst1.EXTERNESDOKUMENT_id_seq from SYSCAT.TABLES fetch first 1 rows only
2026-02-12 16:10:32,309 INSERT INTO db2inst1.EXTERNESDOKUMENT (id,version,titel,kategorie,firma_id) VALUES (656150,1,'Buchungsbeleg',98,181)
2026-02-12 16:10:32,309 (0.0 s)
2026-02-12 16:10:32,309 UPDATE db2inst1.RECEIPT SET version = 7,ext_dok_id = 656150 WHERE id = 1110364 AND (db2inst1.RECEIPT.version = 6)
2026-02-12 16:10:32,309 (0.0 s)2026-02-12 16:10:32,309 UPDATE db2inst1.BUCHUNGSSATZ SET version = 26,zeitstempel = '2026-02-12 16:09:10.919' WHERE id = 2311776 AND (db2inst1.BUCHUNGSSATZ.version = 25)
2026-02-12 16:10:32,309 (0.0 s)
2026-02-12 16:10:32,309 INSERT INTO db2inst1.BUCHUNGSSATZ_HISTORISCH (buchh_id,buchsatz_id,ts,bearbeiter,grund,datum,dat_leistg,buchungstext,ustIDAbnehmer,ktonr_soll,ktobez_soll,betrag_soll,ktonr_haben,ktobez_haben,betrag_haben,mwstcode_id,ktonr_mwst,ktobez_mwst,betrag_mwst,eu_mwst_prozent,eu_land,beleg_id) VALUES (17602,2311776,'2026-02-12 16:09:10.949','
har...@testheimer-werkzeuge.de','Ä','2026-02-11',NULL,'Buchung mit Beleg ohne 2026-02-12 16:10:34,667 Commit Transaction
And here is a bad one:
2026-02-12 16:25:47,855 select next value for db2inst1.EXTERNESDOKUMENT_id_seq from SYSCAT.TABLES fetch first 1 rows only
2026-02-12 16:25:47,901 INSERT INTO db2inst1.EXTERNESDOKUMENT (id,version,titel,kategorie,firma_id) VALUES (656151,1,'Buchungsbeleg',98,181)
2026-02-12 16:25:47,918 (0.015 s)
2026-02-12 16:25:47,934 UPDATE db2inst1.BUCHUNGSSATZ SET version = 27,zeitstempel = '2026-02-12 16:25:45.386' WHERE id = 2311776 AND (db2inst1.BUCHUNGSSATZ.version = 26)
2026-02-12 16:25:47,948 (0.0 s)
2026-02-12 16:25:47,965 INSERT INTO db2inst1.BUCHUNGSSATZ_HISTORISCH (buchh_id,buchsatz_id,ts,bearbeiter,grund,datum,dat_leistg,buchungstext,ustIDAbnehmer,ktonr_soll,ktobez_soll,betrag_soll,ktonr_haben,ktobez_haben,betrag_haben,mwstcode_id,ktonr_mwst,ktobez_mwst,betrag_mwst,eu_mwst_prozent,eu_land,beleg_id) VALUES (17602,2311776,'2026-02-12 16:25:45.464','
har...@testheimer-werkzeuge.de','Ä','2026-02-11',NULL,'Buchung mit Beleg ohne Anhang','','1800','Bank',50,'1610','Kasse 1',50,NULL,NULL,NULL,0,NULL,NULL,1110364)
2026-02-12 16:25:50,308 Commit Transaction
In both cases, I had attached a new externaldocument to the Receipt and committed.
In case #1 the two DatabaseRow objects differ in RowMap>>#additiveDifferencesFrom:into:.
I tried to trick Glorp by changing the timestamp in the Receipt before committing when I attach an ExternalDocument, but even this doesn't trigger an UPDATE.
I also made sure that the Object in memory always has the externesDokument inst var set correctly during the whole preCommit phase and afterwards. Since I do a refresh after the commit, the variable gets reset to nil by the refresh. I can see that the database row has a NULL after the commit and before the refresh (anything else would be a miracle given the sql statements (not) being issued).
I'll keep digging. Thanks for your input anyways. I need to find out where the Row for the changed object is being created and when/where it would get updated with the id of the INSERTED ExternalDocument. Maybe when I get there, I will understand why it is not updated in some cases.
If nothing helps. I will probably have to somehow make this a seqzuence of two commits, something that refreshes the external document from the db and brutally sets its id in the Receipt in a second commit.... Cowardish and hard to document/underastand in maintenance mode, but the bug itself is annoying enough to justify even ugly hacks.