[odb-users] Polymorphism and lazy/weak pointers

Boris Kolpackov boris at codesynthesis.com
Mon Jan 30 10:15:32 EST 2012

Hi Andreas,

Andreas Gerasch <gerasch at informatik.uni-tuebingen.de> writes:

> Do you know if polymorphism works together with lazy loading?

Not out of the box. An "unloaded" lazy pointer stores the object
id and uses the standard database::load() function to load it when
requested. At the moment the way to handle polymorphism in lazy
pointers would be to create your own version of a lazy pointer
which uses your getObjectByID() function instead of standard
load(). There is a bit of work but you can use the boost
implementation as a guide.

Also, we are planning to add support for polymorphic inheritance
in the next release of ODB (not 1.8.0 that is coming our tomorrow;
the version after that). So if you can wait for a few months, then
that could be another option. I can also let you know as soon as we
have something to try, if your are interested.

> Second, is there a possibility to change the caching of objects in a  
> session from shared to weak without changing the pointer types of the  
> objects? 

No, the session uses the object pointer. Plus you cannot use a weak
pointer as an object pointer. Though I kind of see why someone would
want to use a weak pointer in the session. On the other hand, in the
future, session may become more than just an object cache (e.g., we
may use it to track dirty objects if we decide to support auto-flushing)
in which case weak pointers won't really work. Perhaps a better approach
would be to allow custom eviction decisions. For example, you could
provide a callback that checks the reference count and if it is 1,
then you could remove the object from the session. This would be
pretty much equivalent to the lazy pointer semantics. What do you


More information about the odb-users mailing list