Hi Sebastiaan,
As Michiel mentioned above, it is better to only use persistent object in this case, so if user selects something, user will save it and that is it, if the user does not want something, he can cancel changes. So no need for additional non-persistent entity.
Hello Sebastiaan ;)
In my opinion this is a great pattern you've described.
The two entities, while sharing some data, serve fundamentally different purposes and have different lifecycles. Trying to merge them into a single entity can lead to a messy and fragile system.
This approach follows the Separation of Concerns principle, which is key to clean software architecture.
PageContext
(The "Working Copy"): Its job is to manage the current state of the user interface. It's a short-lived, in-memory object. It needs to be highly responsive and reflect immediate user actions, like selecting a different item from a dropdown, even if that choice isn't meant to be saved yet.
UserPreferences
(The "Saved Master Copy"): Its job is to provide long-term persistence for a user's default settings. It's fetched from the database and only changes when the user explicitly saves their preferences.