Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions java/change-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optimize Changelogs for Associated Entities


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
Expand Down