[odb-users] Problem with session cache and weak_ptr

Boris Kolpackov boris at codesynthesis.com
Thu May 12 19:49:24 EDT 2016


Hi Marcel,

Marcel Nehring <mne at qosmotec.com> writes:

> 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?).

Added this paragraph:

"Note that to initialize a lazy pointer to a persistent object from its eager
pointer one must use the constructor or reset() function with the database as
its first argument. The database is required to support comparison of unloaded
lazy pointers to persistent objects."


> 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.

Yes, there is no magic in ODB ;-)

In a sense you are violating the interface: you are saying (by calling
reset() with the database) that this object is persistent (and thus has
a valid object id) when in reality this is not the case.

The fix would be to first persist the object and then assign it to the
lazy pointer.

Boris



More information about the odb-users mailing list