AW: [odb-users] Problem with session cache and weak_ptr
mne at qosmotec.com
Wed May 11 06:52:34 EDT 2016
I investigated this problem a bit more and have to change my description a bit.
I was not aware of the fact that a simple assignment to a lazy pointer from its eager counterpart is not sufficient (maybe we could add a corresponding paragraph to the manual?). When I use the reset method instead and provide both, the eager pointer and the odb::database instance the observable behavior slightly changes:
1) The lazy weak pointer gets reset to a transient object.
2) The transient object gets persisted.
3) The lazy weak pointer expires.
4) A call to loaded() returns false while a call to get_eager() returns an empty/expired pointer.
According to the manual this means the lazy pointer is an "unloaded pointer to persistent object".
Trying to load it, however, fails since the database id stored inside the lazy weak pointer was not updated and thus load() results in an "object not persistent" exception being thrown.
So I still guess the problem is that the lazy weak pointer does not get informed that the object it points to changed from transient to persisted state.
Another question, rather out of curiosity. Why does a lazy pointer need to know the database? Since we need to be inside a transaction when calling load couldn't we get it from there?
More information about the odb-users