> On Mar 17, 2018, at 07:34, David Ohsie <
david...@gmail.com> wrote:
> I know that it is not allowed to insert an object into MapDB and then mutate that object.
I wouldn’t say it’s not allowed. It just doesn’t behave the way you might expect. When you put the object into MapDB it is stored in its present form at the time of the function call. Subsequent changes to the object (instance) will not be reflected in the MapDB unless you call put() again. However, MapDB can cache objects to avoid repeatedly reading them from its own data storage mechanism. So getting an object from MapDB, modifying it, and then calling get() again with the same key will yield an instance with unpredictable contents.
> Question: What if you read an object out of a MapDB map (say you do a get() on an HTreeMap). Is the object that you get() a copy that is safe to mutate? Or could it be a reference which is unsafe to mutate?
It is not entirely “unsafe” to mutate it, it just might behave differently than you expect for certain sequences of actions. As mentioned above, there is an “instance cache" that is enabled by default. If you modify an object received from MapDB and then get that same object again from MapDB, it’s unpredictable whether it will hand you the same instance you modified or a new instance made from the pre-modification data in MapDB.
The above description is based on my understanding of the architecture and past experience. I am not an expert on the internals so it is possible that I’m not 100% correct on the details.
-Andrew