datanucleus / datanucleus-core

DataNucleus core persistence support - the basis for anything in DataNucleus
124 stars 73 forks source link

Investigate only wrapping some mutable fields when accessed #466

Open andyjefferson opened 2 years ago

andyjefferson commented 2 years ago

The wrapping of mutable fields is performed in several places in the codebase. Whilst we absolutely need to wrap any field before handing it to the user (when managed by a StateManager), if we are simply querying for objects and loading fields we don't necessarily need to wrap them at that point since the field may not be accessed before detaching for example. Consider other use-cases and only wrap fields when required.

andyjefferson commented 2 years ago

The typical use-case is a query retrieves a field value. If the field is enhanced as a normal access (as opposed to getViaCheck or getMediate) then isLoaded() will not be called allowing interception of the value, so the value has to be in a wrapped state at that point.

What could be possible is to allow marking a transaction as read-only and in that case anything returned to the user could be returned unwrapped.