I have a button on a screen that creates some data, via dataManager.create(…) and then someDc.getMutableItems.add(…) - it seems when this is done, the entity log is not written to?
Is there a way to cause that to happen? We definitely need it in our application.
Normally all persist operations that go at some point through the CUBA DB abstractions like DataManager or data containers will incoperate the auditing fuctionalities. Only when you execute lower level abstractions like direct SQL e.g you can programmatically work around that.
So in case you found a situation where audit log is not working for me it sounds more like a bug in the fw. The whole idea is to hide these cross cutting concerns behind the API and make it transparent to app developers…
Perhaps you can provide an example together with the audit log configuration exported as JSON via entity inspector.
The dc in question is attached to a table on the screen this is from, which if of course then persisted when the user hits Ok. The entity log for PatientMeasurement is never getting the Created entries.
Ok, I’ve easily created a super-simple example. Just go in, set up the entity log to auto/all for both Master and Detail. Create a new Master, save it (because if you don’t, you get a “IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST” - I’ll try to figure that out at another time) - then go back in, use the “Test…” button to create a bunch of Details… Save the whole thing. Then check the entity log. I get nothing referencing Detail when I do it. testentitylog.zip (83.8 KB)
Interestingly, fixing the “IllegalStateException” when adding Details to a new (not yet persisted Master) also fixes the issue of the entity log not getting written.
I see a ton of examples out there of using dataManager.create(…) … and I’ve never seen one followed by dataContext.merge(…) but it seems if you don’t do that you get two problems (1) entity log not getting written and (2) when it’s done on a new master, you get the “IllegalStateException” issue I mentioned in my reply up there.
So the pattern that solves both of those is:
SomeEntity se = dataManager.create(SomeEntity.class);
se.setX(...);
// (more of that)
se = dataContext.merge(se);
// (if needed, for example adding to a detail table/etc)
someEntityDc.getMutableItems().add(se);