diff --git a/java/change-tracking.md b/java/change-tracking.md index 4a96b28f6..b81f9c8a5 100644 --- a/java/change-tracking.md +++ b/java/change-tracking.md @@ -436,6 +436,45 @@ public class ChangeTrackingHandler implements EventHandler { You can query the change log entries via CQN statements, as usual. +## Tips and Tricks + +### Entities from Remote Services + +Change Tracking expects that everything is stored in the local database. +If you need to model an association to the remote entity, the only possible option is to track changes for its foreign key. + +:::warning Configuration change required! +Enable [optimization for path expressions](/releases/2025/aug25#optimized-path-expressions). +::: + +Let's take the following model as an example: + +```cds +@cds.external: true +entity Remote { + key ID : UUID; + ... +} + +entity Local { + key ID : UUID; + toRemote : Association to Remote; +} +``` + +You model the association like this: + +```cds +entity Local { + key ID : UUID; + toRemote : Association to Remote @changelog: [toRemote.ID]; // [!code focus] +} +``` + +The entity's primary key is the only field you can use here, as rest of the association's target fields is not readable with standard persistence. The change log will contain one entry for the field `toRemote` just like the other associations with [human-readable values](#human-readable-values-for-associations). + +If you need a custom identifier, it is up to you to implement in a custom handler. + ## Things to Consider when Using Change Tracking - Consider the storage costs of the change log. The change log can grow very fast and can consume a lot of space